I have a class Term.java and it maps to a table in mysql. I want to use metamodel statements in query like the following, but it complains that "Term_" is not an available variable.
public List<Term> findAllOrderedByName() {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Term> criteria = cb.createQuery(Term.class);
Root<Term> term = criteria.from(Term.class);
criteria.select(term).orderBy(cb.asc(term.get(Term_.name)));
return em.createQuery(criteria).getResultList();
}
I have this dependency in my POM:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>
And the container is JBoss. What's the problem here? Thank you.
Edited:
In Eclipse, click "project->JPA->canonical metamodel (JPA2.0)" and specify the source folder, and I got the class automatically generated in Eclipse. Is this the right way?
@Generated(value="Dali", date="2016-02-29T14:56:11.460-0800")
@StaticMetamodel(Term.class)
public class Term_ {
public static volatile SingularAttribute<Term, Integer> id;
public static volatile SingularAttribute<Term, String> name;
public static volatile ListAttribute<Term, Context> contexts;
}