字符串字段的jpametamodel null SingularAttribute



我有类实体:

@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;

...
}

用法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);

这是Patient_MRN的正确工作。但我有Patient_.firstName.字段的运行时NullPointerException

jpametamodel生成与hibernate jpamodelgen版本5.4.30.最终

生成的类

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";
}

它的工作:

Predicate pFn = cb.equal(root.get("FirstName"), fn);

相关内容

  • 没有找到相关文章

最新更新