I have class entity:
@Entity public class Patient { private int id; private int mrn; private String firstName; private String lastName; private String middleName; private int ssn; private Date dateOfBirth; private Date dateOfDeath; private Sex sex; private Set<Visit> visits; ... }
Usage jpametamodel:
EntityManager em = emf.createEntityManager(); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Patient> cq = cb.createQuery(Patient.class); Root<Patient> root = cq.from(Patient.class); // its work Predicate prMrn = cb.equal(root.get(Patient_.MRN), mrn); // NullPointerException Predicate pFn = cb.equal(root.get(Patient_.firstName), fn);
its correct work with Patient_.MRN. But I have runtime NullPointerException for field Patient_.firstName.
jpametamodel generated with hibernate-jpamodelgen version 5.4.30.Final
Advertisement
Answer
generated class
public abstract class Patient_ { public static volatile SingularAttribute<Patient, String> firstName; public static volatile SingularAttribute<Patient, String> lastName; public static volatile SetAttribute<Patient, Visit> visits; public static volatile SingularAttribute<Patient, Date> dateOfDeath; public static volatile SingularAttribute<Patient, Integer> MRN; public static volatile SingularAttribute<Patient, String> middleName; public static volatile SingularAttribute<Patient, Date> dateOfBirth; public static volatile SingularAttribute<Patient, Integer> id; public static volatile SingularAttribute<Patient, Integer> SSN; // its erorr! right "FirstName" public static final String FIRST_NAME = "firstName"; public static final String LAST_NAME = "lastName"; public static final String VISITS = "visits"; public static final String DATE_OF_DEATH = "dateOfDeath"; public static final String M_RN = "MRN"; public static final String MIDDLE_NAME = "middleName"; public static final String DATE_OF_BIRTH = "dateOfBirth"; public static final String ID = "id"; public static final String S_SN = "SSN"; }
it’s work:
Predicate pFn = cb.equal(root.get("FirstName"), fn);