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
Person_
is a metamodel generated through the classPerson
. 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– Roque Santos
That’s Roque, that’s right. Thank you.
– wen-dell