public class Merchant { public enum Service { A, B, C, D, E, F, }
@CollectionOfElements(fetch=FetchType.LAZY) @JoinTable(name = "Merchant_Service", joinColumns = {@JoinColumn(name = "mId")}) @Column(name="service", nullable=false, columnDefinition="smallint(2)") @Enumerated(value=EnumType.ORDINAL) public Set<Service> getServices() { return services; }
}
Every merchant provides a set of Service, such as {A, B, D}, {A, D, F}, etc.
Using Criteria API: Query: return all Merchants that provide service A and D, ie, their services containing subset {A, D}.
Restrictions.contains(propertyName, collectionValue).
The criteria API does not provide such method.
Thanks for help. Dave
|