I have two tables, DVD and Contact.
A DVD can be rented to a contact and a contact can rent many DVD's.
The many to one link (dvd-->contact)
works fine.
But the other way fails: (contact-->dvd)
This is the contact mapping:
<set name="dvds" inverse="true">
<key column="contactId"/>
<one-to-many class="Dvd"/>
</set>
Here is setter getter for Contact:
private Set<Dvd> dvds = new HashSet<Dvd>();
public Set<Dvd> getDvds(){
return dvds;
}
public void setDvds(Set<Dvd> dvds){
this.dvds=dvds;
}
When I try to get the DVD rented from a contact with this:
HashSet<Dvd> tt = (HashSet<Dvd>)dds;
I get an Exception:
java.lang.ClassCastException: org.hibernate.collection.PersistentSet
cannot be cast to java.util.HashSet
What does the Exception mean and how do I fix it?
Edit: This solved my problem:
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)