enum FooType:
public enum FooType {
//...
}
Entity Foo (containing attribute FooType):
@Entity
public class Foo {
protected FooType type;
@Enumerated(EnumType.STRING)
public FooType getType() { return type; }
public void setType(FooType type) { this.type = type; }
}
DAO method to find all Foos by FooType:
public List findAllFooByType(FooType type) {
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(Foo.class);
Root invitation = cq.from(Foo.class);
cq.where(
cb.equal(invitation.get(Foo_.type), type));
cq.select(invitation);
TypedQuery typedQuery = getEntityManager().createQuery(cq);
return typedQuery.getResultList();
}
References
http://blogs.oracle.com/Lance/entry/generating_the_jpa_2_0
No comments:
Post a Comment