I'm working with a large existing application, converting to using Hibernate for persistence. The application runs in Tomcat, so I'm not really in a J2EE container environment, and we're not using Spring either. Integrating Spring is really way out of scope for the current project and isn't really an option.
I've looked at various examples of how people are writing DAOs for their persistence layer with Hibernate, and some are simply using SessionFactory to create Sessions and some are using EntityManager. I can see how to bootstrap an EntityManager but I'm wondering if I really need to?
What are the consequences of NOT using EntityManager?
You can use the Hibernate Session
, but the API is Hibernate specific. The EntityManager
allows portability between JPA vendors, which although appealing in theory, it's not really feasible in practice as you will need specific API anyway (pooled-lo optimizer, advanced locking features).
So, whatever you could do with EntityManger
you can do with the Hibernate Session
, but not the other way around.