I have tried to access the MetaModel entity attributes/variables using the code below:
CriteriaQuery<User> criteria = builder.createQuery(User.class);
Metamodel m = entityManager.getMetamodel();
EntityType<User> User_ = m.entity(User.class);
Root<User> userRoot = criteria.from(User.class);
criteria.where(builder.equal(userRoot.get(User_.email)), user.getEmail());
but email cannot be resolved or is not a field. Is it mandatory to create StaticMetaModel class for User class. i.e., "User_" ???
If YES, please see the link http://docs.oracle.com/javaee/6/tutorial/doc/gkjbq.html here, you can find the below code:
CriteriaQuery<Pet> cq = cb.createQuery(Pet.class);
Metamodel m = em.getMetamodel();
EntityType<Pet> Pet_ = m.entity(Pet.class);
Root<Pet> pet = cq.from(Pet.class);
cq.where(cb.equal(pet.get(Pet_.name), "Fido"));
Please help me here.