-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Error Deleting Collections which are child elements
PostPosted: Sun Nov 13, 2005 4:19 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 4:37 pm
Posts: 27
Location: Washington DC
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


Top
 Profile  
 
 Post subject: delete-orphan?
PostPosted: Mon Nov 14, 2005 6:10 am 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
Try to set cascade="all-delete-orphan" in the many-to-one end.
Otherwise, I think that only the column PARENT_ID gets set to null.

Code:
<set
name="childProps"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
>
<key>
<column name="PARENT_ID" />
</key>
<one-to-many
class="ChildClass"
/>
</set>

_________________
hth,
Heinz
Don't forget to rate if this helped


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.