Hi People, I'm a newbie with hibernate and I found a problem with a relation many-to-many
I'm using netbeans 6.5 and I have generated the class and the mapping files for hibernate.
In the db I have made 3 table, "groups", "functionsToGroup" and "functions"; into "functionsToGroup" I have the reference to group id and functions id there relation is 0....N on both side.
Netbeans generate 2 java class "Groups.java" and "Functions.java" and put inside "Groups.java" a HashSet of functions and inside Functions.java " an hashset of Group.
In my java code , I try to
Code:
session = startTransaction();
Transaction transaction = session.getTransaction();
Gruppo gruppo = (Gruppo) session.load(Gruppo.class, idGruppo);
for (KeyValue kv : functions) {
Funzione fx = (Funzione) session.createQuery("from Funzione where CODICE_FUNZIONE=:code").setString("code", kv.getValue()).uniqueResult();
gruppo.getFunziones().add(fx);
}
session.save(gruppo);
transaction.commit();
I can see all the select made by hibernate engine, but I cannot find the insert into relation table (this's my target)
Code:
"Gruop.hbm..."
<set name="funziones" inverse="true" table="funzione2gruppo" cascade="all">
<key>
<column name="ID_GRUPPO" not-null="true" />
</key>
<many-to-many entity-name="it.hibernate.beans.Funzione">
<column name="ID_FUNZIONE" not-null="true" />
</many-to-many>
</set>
"Function.hbm..."
<set name="gruppos" inverse="false" table="funzione2gruppo">
<key>
<column name="ID_FUNZIONE" not-null="true" />
</key>
<many-to-many entity-name="it.hibernate.beans.Gruppo">
<column name="ID_GRUPPO" not-null="true" />
</many-to-many>
</set>
Where am I wrong?
Thanks a lot for your help