What is the difference between javax.persistence.criteria and org.hibernate.criterion packages?

1.3k Views Asked by At

Recently my team upgraded from Hibernate 3 to Hibernate 5 so I am working on the migration stuff. Now when I try to use CriteriaQuery class, eclipse shows that it can be imported from both 'javax.persistence.criteria' as well as 'org.hibernate.criterion' packages.

CriteriaQuery cq = getSession().getCriteriaBuilder().createQuery(MyClass.class);

So I am a bit confused over here about which one to use.

Also it would be very helpful if someone could explain the difference between the two(JPA and Hibernate) as I am unclear about this conceptually and have a hard time getting to know whats happening underneath.

1

There are 1 best solutions below

2
On BEST ANSWER

From Hibernate docs:

This appendix covers the legacy Hibernate org.hibernate.Criteria API, which should be considered deprecated.

You should use the JPA criteria query, which was heavily influenced by Hibernate. At the beginning, there were quite a bit of differences (for example, LAZY vs EAGER fetch as defaults on mappings.) by the time Hibernate 5 came around, most of the differences have been resolved by Hibernate adopting JPA behavior. As far as I understand most Hibernate behavior is now either the same or similar to the JPA standards, and is only maintained for legacy purposes.