Hi guys,
i need help with following:
I have 2 entities (Uzivatel,Role) with many-to-many relationship.
I am getting duplicate rows when updating my Uzivatel table - UzivatelDAO code: getHibernateTemplate().update(uzivatel);
It may be that i am trying to update the joiin table (Relace_role_uzivatel) with value which is already there, but I want Hibernate to not allow this.
Another strange thing, When I tried to put inverse="true" in Uzivatel.hbm.xml, the join table dont get updated at all...
Appreciate your comments on this. thx
Uzivatel.hbm.xml:
Code:
<set name="role" table="Relace_role_uzivatel">
<key column="uzivatel_id"/>
<many-to-many column="role_id"
class="cz.datasys.gpsmonitor.service.Role"/>
</set>
Uzivatel.java:
Code:
private Set role = new HashSet();
Role.hbm.xml:
Code:
<set name="uzivatele" inverse="true" table="Relace_role_uzivatel">
<key column="role_id"/>
<many-to-many column="uzivatel_id"
class="cz.datasys.gpsmonitor.service.Uzivatel"/>
</set>
Role.java:
Code:
private Set uzivatele = new HashSet();
Usage:
Code:
Role role = new Role(roleName,roleId);
uzivatel.getRole().add(role);
uzivatelDAO.updateUzivatel((Uzivatel) o);