I have been moving around with this question and the bird eye difference between Hibernate SessionFactory and JPA EntityManagerFactory is that JPA is standard. You can use it without being afraid of underlying ORM. yet it calls the underlying sessionFactory under the hood.(Correct me if i am wrong)
But if someone knows that he has just to stick with hibernate as a ORM in the future, then what should he choose from these two Factories and why?
Secondly, what are the other differences between these two with respect to performance, features, stability etc?
So, the SessionFactory is also a JPA EntityManagerFactory. Both the SessionFactory and the EntityManagerFactory contain the entity mapping metadata and allow you to create a Hibernate Session or a EntityManager. Just like the SessionFactory and EntityManagerFactory, the Hibernate Session extends the JPA EntityManager.
In contrast, if you use hibernate’s session factory, it is tied to hibernate APIs and ca not migrate to new vendor easily. One dis-advantage of using the standard implementation is that, it is not providing the advanced features. There is not much control provided in the EntityManager APIs.
Regarding differences between Session and EntityManager methods, we should note that Session has more methods to analyze its internal state. The single common method is called isOpen and permits to check if Session or EntityManager is open.
It can be created through providing objects of Configuration. This will contain all the database property details which are pulled from either hibernate.properties file or hibernate.cfg.xml file. Session objects consist and are like a factory in SessionFactory.
You should prefer the standard JPA API over the proprietary Hibernate one, for several reasons:
Anyway, most of the effort is in mapping the entities themselves, and that is done using standard JPA annotations, even when using the Session API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With