0

Which of these options is the better? EntityManager is JPA and if I decide to go for another implementation some day it would be easier. What could be the reason to go for hibernate Session?

4

1 に答える 1

1

With EntityManager, you have the benefit of having a standard interface, and the JPA2 criteria API. If necessary, you can always get the underlying Hibernate native session, and use that in addition.

With the native Hibernate session, you get more methods (but it's debatable if they're useful or not): save(), saveOrUpdate(), etc. and the native Hibernate criteria API which, IMHO, is easier to use, although less type-safe, than the JPA2 criteria API.

Unless you have to integrate with awhole bunch of code or APIs that use the native Hibernate API, I would go with the EntityManager interface.

于 2012-09-23T09:52:11.463 に答える