Hello, I am trying to create a type-safe criteria query.
this is my function:
Code:
@Override
public List<QuestionnaireClient> read(String questionnaireId) {
CriteriaQuery<QuestionnaireClient> criteria = getEntityManager().getCriteriaBuilder().createQuery(QuestionnaireClient.class);
Root<QuestionnaireClient> client = criteria.from(QuestionnaireClient.class);
Path<String> questionnaireIdPath = client.get(QuestionnaireClient_.questionnaireId);
criteria.where(getEntityManager().getCriteriaBuilder().equal(questionnaireIdPath, questionnaireId));
TypedQuery<QuestionnaireClient> query = getEntityManager().createQuery(criteria);
List<QuestionnaireClient> pesristedClients = query.getResultList();
return pesristedClients;
}
I get a null pointer exception on line 3:
Path<String> questionnaireIdPath = client.get(QuestionnaireClient_.questionnaireId);
Now, this is the entity:
Code:
@Entity
@Table(name = "clients")
@Inheritance(strategy = InheritanceType.JOINED)
public class QuestionnaireClient implements Serializable {
/* --- Members --- */
/** Serial version unique id */
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
private String id;
@Version
private int version;
@Enumerated(EnumType.STRING)
private IdType idType;
private String clientId;
private String fullName;
private String shortPassportId;
@Enumerated(EnumType.STRING)
private RelationToAccount accountRelation;
private boolean isParticipating;
private boolean isEditable;
private String questionnaireId;
This is the meta model class:
Code:
@StaticMetamodel(QuestionnaireClient.class)
public class QuestionnaireClient_ {
public static volatile SingularAttribute<QuestionnaireClient, Long> serialVersionUID;
public static volatile SingularAttribute<QuestionnaireClient, String> id;
public static volatile SingularAttribute<QuestionnaireClient, Integer> version;
public static volatile SingularAttribute<QuestionnaireClient, String> idType;
public static volatile SingularAttribute<QuestionnaireClient, String> clientId;
public static volatile SingularAttribute<QuestionnaireClient, String> fullName;
public static volatile SingularAttribute<QuestionnaireClient, String> shortPassportId;
public static volatile SingularAttribute<QuestionnaireClient, String> accountRelation;
public static volatile SingularAttribute<QuestionnaireClient, Boolean> isParticipating;
public static volatile SingularAttribute<QuestionnaireClient, Boolean> isEditable;
public static volatile SingularAttribute<QuestionnaireClient, String> questionnaireId;
}
I also tried to create the metamodel class with only the wanted line which is:
public static volatile SingularAttribute<QuestionnaireClient, String> questionnaireId;
I got the same result.
Can anyone please help me?
Thank you,
Ido