Entity object Foo containing enum MyEnum:
@Entity
class Foo implements Serializable {
// ....
private MyEnum e;
@Enumerated(EnumType.STRING)
public MyEnum getE() {
return e;
}
public void setE(MyEnum e) {
this.e = e;
}
// ....
}
JPA Criteria query: find all Foo containing MyEnum==method parameter e:
public List findByMyEnum(MyEnum e) {
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(Foo.class);
Root foo = cq.from(Game.class);
cq.where( cb.equal(game.get(Foo_.e), e) );
cq.select(foo);
TypedQuery typedQuery = getEntityManager().createQuery(cq);
return typedQuery.getResultList();
}
No comments:
Post a Comment