Hi all.
I have this scenario:
i have two entities:
OrganoRub and
NominativoRub; the relation between them is many to many...that is an OrganoRub can have from 0 to infinite NominativoRub and viceversa a NominativoRub can have from 0 to infinite OrganoRub.
Besides i need that when i create an OrganoRub and this OrganoRub has a non persisted NominativoRub associated this NominativoRub must be created.
Then if i delete an OrganoRub the associated Nominativo must not be deleted; only the row in the join table must be deleted; the same for NominativoRub..if a NominativoRub is deleted the eventual OrganoRub associated must not be deleted; only the the NominativoRub is deleted and the row in the join table.
Now i have used this mapping files:
NominativoRub
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="it.eng.intranet.bean.NominativoRub" table="NOMINATIVO_RUB">
<id name="idNominativo" type="int" column="NOMINATIVO_ID" unsaved-value="0">
<generator class="native"/>
</id>
<property name="cognome" column="COGNOME" type="string"/>
<property name="matricola" column="MATRICOLA" type="int" length="10"/>
<property name="indirizzoIp" column="INDIRIZZO_IP" type="string" length="15"/>
<property name="nome" column="NOME" type="string"/>
<property name="funzione" column="FUNZIONE" type="string"/>
<property name="indirizzo" column="INDIRIZZO" type="string"/>
<!--many-to-one name="sedeRub" column="SEDE_FK" not-null="false" class="it.eng.intranet.bean.SedeRub"/-->
<!-- relazione *-* con la tabella ORGANO; un nominativo può avere diversi organi associati; esso potrebbe essere responsabile di diversi organo -->
<set name="organi" inverse="true" lazy="false" table="NOMINATIVO_ORGANO">
<key column="ID_NOMINATIVO"/>
<many-to-many class="it.eng.intranet.bean.OrganoRub" column="ID_ORGANO"/>
</set>
</class>
</hibernate-mapping>
OrganoRubCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="it.eng.intranet.bean.OrganoRub" table="ORGANO_RUB">
<id name="idOrgano" type="int" column="ORGANO_ID">
<generator class="native" />
</id>
<property name="codOrgano" column="CODICE_ORGANO" type="string" not-null="false"/>
<property name="descrizione" column="DESCRIZIONE" type="string" length="10000" not-null="true"/>
<!-- relazione *-1 con la tabella NOMINATIVO >
<one-to-one name="nominativoRub" class="it.eng.bean.NominativoRub"/-->
<!-- Relazione 0->* con Nominativo; un organo più avere 1 o N responsabili -->
<set name="responsabili" cascade="save-update" table="NOMINATIVO_ORGANO">
<key column="ID_ORGANO"/>
<many-to-many class="it.eng.intranet.bean.NominativoRub" column="ID_NOMINATIVO"/>
</set>
</class>
</hibernate-mapping>
This is my environment:
DB: MySql 5
Hibernate version: 3.2.5
Spring version: 2.0.6
JVM: 1.4.2_12
Now I'm able in deleteing OrganoRub without deleting NominativoRub (only the row in the join table is deleted) but if i delete the NominativoRub if it has some OrganoRub associated i can't delete it....i need to delete it and the row in the join table....is there any solution?
Thanks to all.
Regards,
Angelo