Hello
The problem is that when I try to delete a Country that has a Visa (with a many-to-many relationship) I get an exception because he try to delete directly the Country in the table without deleting first the link between the Country and the Visa is the table country_has_visa.
How to force NHibernate to delete all links between a Visa and a Country object in the table country_has_visa before deleting a Country or Visa object ?
Without that I broke always the constraint of the foreign key in the country_has_visa table.
Thanks in advance for your help !!!
Hibernate version:
last version
Mapping documents:
Code:
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.0">
<class name="ng.bcngGeo.Visa, mapping" table="visa">
<id name="id" column="id_visa" unsaved-value="0">
<generator class="sequence" />
</id>
<property name="name" column="name"/>
<set name="countries" lazy="true" inverse="false" cascade="none" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" table="country_has_visa">
<key column="visa_id"/>
<many-to-many class="ng.bcngGeo.Country,mapping" column="country_id"/>
</set>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.0">
<class name="ng.bcngGeo.Country, mapping" table="country">
<id name="code" column="code_country" unsaved-value="0">
<generator class="sequence" />
</id>
<property name="codeIso" column="code_iso"/>
<property name="name" column="name"/>
<set name="visas" lazy="true" inverse="true" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" table="country_has_visa" cascade="none">
<key column="country_id"/>
<many-to-many class="ng.bcngGeo.Visa,mapping" column="visa_id"/>
</set>
<set name="vaccinations" lazy="true" inverse="false" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" table="country_has_vaccination">
<key column="country_id"/>
<many-to-many class="ng.bcngGeo.Vaccination,mapping" column="vaccination_id"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Exception non gérée : NHibernate.ADOException: could not delete: [ng.bcngGeo.Country#6] --
-> System.Data.OracleClient.OracleException: ORA-02292: violation de contrainte (MAPPING.F
K81778864BACBF007) d'intégrité - enregistrement fils existant
à System.Data.OracleClient.OracleConnection.CheckError(OciErrorHandle errorHandle, Int3
2 rc)
à System.Data.OracleClient.OracleCommand.Execute(OciStatementHandle statementHandle, Co
mmandBehavior behavior, Boolean needRowid, OciRowidDescriptor& rowidDescriptor, ArrayList&
resultParameterOrdinals)
à System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean needRowid, Oci
RowidDescriptor& rowidDescriptor)
à System.Data.OracleClient.OracleCommand.ExecuteNonQuery()
à NHibernate.Impl.NonBatchingBatcher.AddToBatch(Int32 expectedRowCount)
à NHibernate.Persister.EntityPersister.Delete(Object id, Object version, Object obj, IS
essionImplementor session)
Name and version of the database you are using:
Oracle 10 g