I have an application that uses Hibernate 4.x, and it is currently using the native Hibernate APIs (meaning that I have a SessionFactory
and Session
s). I just noticed that the existing Criteria API is deprecated in favor of JPA's (superior) Criteria API:
Hibernate offers an older, legacy
org.hibernate.Criteria
API which should be considered deprecated. No feature development will target those APIs. Eventually, Hibernate-specific criteria features will be ported as extensions to the JPAjavax.persistence.criteria.CriteriaQuery
.
I don't want to have to convert my application over to using EntityManager
directly (even though it's easy to get a Hibernate Session
from there) because we have a large amount of custom Hibernate configuration logic that will need to be replaced. Despite that, I definitely want to start using the JPA Criteria APIs, since the old APIs are deprecated (and will presumably disappear at some random point in the future, if past Hibernate releases are any indication) and they also provide much better type safety.
How can I use the new CriteriaQuery/CriteriaBuilder API, if I'm using SessionFactory/Session?