Using EntityManagerFactory and SessionFactory together at the same app for same database

27 Views Asked by At

Is it bad practice to use EntityManagerFactory and SessionFactory together at the same app for same database? Or it's better to use only one of them?

1

There are 1 best solutions below

0
Davide D'Alto On

EntityManageFactory is part of the JPA specification so it's more portable. SessionFactory is Hibernate specific but the implementation is a subclass of EntityManagerFactory anyway.

Using one or the other (or both) depends on the requirements, how you create the factory and which API you prefer. Hibernate will return an implementation that's compatible with both interfaces anyway.