0

Since Hibernate 5 no longer supports createCriteria, I cannot figure out how to replace the old session.createCriteria(className.class).add(Restrictions.idEq(id)).list(); idEq() part with CriteriaBuilder. CriteriaBuilder equal method works only if I have attribute name. What I need is query by identifier.

Any ideas?

zlekonis
  • 31
  • 6
  • Related https://stackoverflow.com/questions/40720799/deprecated-createcriteria-method-in-hibernate-5 – Kayaman Jul 18 '18 at 06:55
  • 2
    `session.get(MyClass.class, id)` gets an entity by ID. And of course it doesn't return a list, since there is only one entity with a given ID, by definition of ID. It's also more efficient, since it looks in the cache before doing a useless query. – JB Nizet Jul 18 '18 at 06:56

0 Answers0