Hibernate documentation code not clear

Asked

Viewed 36 times

0

My question is about a code that’s in the Hibernate documentation. I simply couldn’t understand the notation they used in the criteria.Where() part. Just notice how it was placed: Person_.name. Can anyone explain to me? Follow the passage where this occurs that I spoke:

CriteriaBuilder builder = entityManager.getCriteriaBuilder();

CriteriaQuery<Person> criteria = builder.createQuery( Person.class );
Root<Person> root = criteria.from( Person.class );
criteria.select( root );
criteria.where( builder.equal( root.get( Person_.name ), "John Doe" ) );

List<Person> persons = entityManager.createQuery( criteria ).getResultList();

I’ve tried to do the same, but here it says "Cannot be resolved to a variable" in this code snippet.

The documentation is recent, follow the link: Documentation of Hibernate

  • 1

    Person_ is a metamodel generated through the class Person. See if this link helps you understand about metamodels and how to generate them: https://docs.jboss.org/hibernate/orm/5.0/topical/html/metamodelgen/MetamodelGenerator.html

  • That’s Roque, that’s right. Thank you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.