Is the criteria api of eclipselink jpa2 supported for java se 6 projects? If not, that’s my problem.
Do I need to specify anything special to the criteria api in the persistence.xml?
This is my criteria query:
final EntityType<Meaning> Meaning_ = em.getMetamodel().entity(Meaning.class);
final CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Integer> cq = cb.createQuery(Integer.class);
final Root<Meaning> meng = cq.from(Meaning.class);
cq.where(meng.get(Meaning_.lastPublishedDate)); //this attributes are not recognized/found
cq.select(meng.get(Meaning_.objId)); // " "
TypedQuery<Integer> q = em.createQuery(cq);
return q.getResultList();
And here is my Meaning entity:
@Entity
public class Meaning implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int objId;
public int getObjId() {
return objId;
}
@Temporal(javax.persistence.TemporalType.DATE)
private Date lastPublishedDate = null;//never
public Date getLastPublishedDate(){
return lastPublishedDate;
}
}
About your code
I didn’t check the correctness of the criteria query itself but, as Chris mentioned, you are mixing static metamodel classes with the
EntityTypethat doesn’t expose what you’re looking for. Assuming your metamodel classes have been generated, remove the first line and import the generatedMeaning_:About generation of the static (canonical) metamodel classes
Here is the Maven setup I’m using to generate the canonical metamodel classes with EclipseLink:
Some comments:
<processor>.-Aeclipselink.persistencexml, the annotation processor complains about thepersistence.xmlnot being present and fail.target(I want acleanto clean it).With this configuration, the static metamodel classes get generated and compiled appropriately.