Im trying to run a basic select record where I assign a value to a pk column
select * from ae_p_pst_c where status_code = "OPEN";
Code:
public class AePPstCPK {
...
@Column(name = "status_code")
public String getStatusCode() {
return (String)attributes[0].getValue();
}
...}
-------------------
@Entity
@Table(name = "ae_p_pst_c")
@IdClass(AePPstCPK.class)
public class AePPstCDTO {
...
@Id
@Column(name = "status_code", nullable = false , length = 20)
public String getStatusCode() {
return (String) getAttribute(AePPstCAttributeName.STATUS_CODE).getValue();
}
...
}
Code:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<AePPstCDTO> cq = cb.createQuery(AePPstCDTO.class);
Root<AePPstCDTO> aePPstCDTORoot = cq.from(AePPstCDTO.class);
cq.where(cb.equal(aePPstCDTORoot.get("statusCode"), "OPEN")); //status Code is a ID column and cant be found in attribute list???
I will get NullpointerException when the code tries to get statusCode from aePPstCDTORoot.
Code:
java.lang.NullPointerException
at org.hibernate.ejb.criteria.path.AbstractPathImpl.unknownAttribute(AbstractPathImpl.java:110)
at org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:218)
at org.hibernate.ejb.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:189)
Can anyone tell me how to write the code so that I can access the ID columns in my query
P.S. It works fine if I use a column that is not the pk column.
-Greg