I have an @Entity which has an @Enumerated field mapped to it:
@Entity
@Table
public class Device implements Serializable {
@I
It seems like a solution to your problem might be along the lines of:
Criteria criteria = factory.getCurrentSession().createCriteria(Device.class);
Disjunction or = Restrictions.disjunction();
for (DeviceType type : DeviceType.values()) {
if (type.isFubar()) {
or.add(Restrictions.eq("typeOfDevice", type));
}
}
criteria.add(or);
return criteria;
Instead of doing where typeOfDevice.fubar = true, we're approaching it more along the lines of where (typeOfDevice = Mobile OR typeOfDevice = OtherFubar OR typeOfDevice = OtherOtherFubar). I realize this isn't the one-liner you were originally shooting for, but I think it answers the question as asked.