Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: HIbernate 3.1
I have a parent class and it has a one-to-many relation to a child class meaning there are a collection of child elements belonging to the parent class.
When i try to delete the parent by setting the identifier of the parent object, it doesn't cascade the call to delete the children.
In my parent class this is mapping i have of the children,
<set
name="childProps"
lazy="true"
inverse="true"
cascade="all"
>
<key>
<column name="PARENT_ID" />
</key>
<one-to-many
class="ChildClass"
/>
</set>
In My child class mapping i have this tag
<many-to-one
name="parentObj"
class="ParentClass"
not-null="true"
>
<column name="PARENT_ID" />
</many-to-one>
Code between the session.open() and session.delete()
<code>
Transaction deleteTransaction = deleteSession.beginTransaction();
//Actual Delete function into the database.
deleteSession.delete(parentObject);
deleteSession.flush();
// Commiting the transaction and closing the session.
deleteTransaction.commit();
</code>
deleteObject above has the ParentObject with ID set on it as i am using assigned identifers.
The errors shown are these:
<b>
15:09:37,527 INFO [STDOUT] Hibernate: select scanpropty_.PARENT_ID, scanpropty_.PARENT_TYPE_ID as PARENT2_2_ from PARENT_TYPES scanpropty_ where scanpropty_.PARENT_TYPE_ID=?
15:09:37,547 INFO [STDOUT] Hibernate: delete from PARENT where PARENT_ID=?
15:09:37,567 WARN [JDBCExceptionReporter] SQL Error: 2292, SQLState: 23000
15:09:37,577 ERROR [JDBCExceptionReporter] ORA-02292: integrity constraint (IMDS_USER.SYS_C007480) violated - child record found
15:09:37,577 WARN [JDBCExceptionReporter] SQL Error: 2292, SQLState: 23000
15:09:37,577 ERROR [JDBCExceptionReporter] ORA-02292: integrity constraint (IMDS_USER.SYS_C007480) violated - child record found
15:09:37,577 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
</b>
Basically the removal is trying to delete the parent without removing the collection.
Thanks,
Surya