I have two tables, a DVD and a contact.
DVDs can be rented to contact, and many DVDs can be rented by contact.
Much in one link (dvd-->contact) works great.
But another way fails: (contact-->dvd)
This is a contact mapping:
<set name="dvds" inverse="true"> <key column="contactId"/> <one-to-many class="Dvd"/> </set>
Here is the setter getter used for the 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 a DVD taken out of 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 to fix it?
Edit: this solved my problem:
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
source share