org.hibernate.QueryException: illegal attempt to dereference collection

billProductSet is a Collection. As such, it does not have an attribute named product. Product is an attribute of the elements of this Collection. You can fix the issue by joining the collection instead of dereferencing it: SELECT count(*) FROM BillDetails bd JOIN bd.billProductSet bps WHERE bd.client.id = 1 AND bps.product.id = 1002

How to define unidirectional OneToMany relationship in JPA

My bible for JPA work is the Java Persistence wikibook. It has a section on unidirectional OneToMany which explains how to do this with a @JoinColumn annotation. In your case, i think you would want: @OneToMany @JoinColumn(name=”TXTHEAD_CODE”) private Set<Text> text; I’ve used a Set rather than a List, because the data itself is not ordered. … Read more

Storing a Map using JPA

JPA 2.0 supports collections of primitives through the @ElementCollection annotation that you can use in conjunction with the support of java.util.Map collections. Something like this should work: @Entity public class Example { @Id long id; // …. @ElementCollection @MapKeyColumn(name=”name”) @Column(name=”value”) @CollectionTable(name=”example_attributes”, joinColumns=@JoinColumn(name=”example_id”)) Map<String, String> attributes = new HashMap<String, String>(); // maps from attribute name to … Read more