-->
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.  [ 1 post ] 
Author Message
 Post subject: Exception: org.hibernate.ObjectDeletedException
PostPosted: Fri Oct 29, 2010 5:31 pm 
Newbie

Joined: Fri Oct 29, 2010 5:15 pm
Posts: 1
Hi all

Am trying to delete an entity but are getting the following error:

org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations)

This is how my entity structures looks:


<class name="dk.blog.model.Blog" table="blog">
<id name="id" column="id">
<generator class="identity"/>
</id>
<property name="title" column="title"/>
<property name="message" column="message"/>
<property name="createDate" column="create_date"/>
<set name="commentSet" inverse="true" cascade="all">
<key column="blog_id"/>
<one-to-many class="dk.blog.model.Comment"/>
</set>
</class>

<class name="dk.blog.model.Comment" table="comment">
<id name="id" column="id">
<generator class="identity"/>
</id>
<property name="message" column="message"/>
<property name="createDate" column="create_date"/>
<many-to-one name="blog" column="blog_id" class="dk.blog.model.Blog"/>
<many-to-one name="user" column="user_id" class="dk.blog.model.User"/>
</class>

<class name="dk.blog.model.User" table="users">
<id name="id" column="id">
<generator class="identity"/>
</id>
<property name="userName" column="username"/>
<property name="password" column="password"/>
<property name="enabled" column="enabled"/>
<property name="email" column="email"/>
<property name="createDate" column="create_date"/>
<set name="commentSet" inverse="true" cascade="all">
<key column="user_id"/>
<one-to-many class="dk.blog.model.Comment"/>
</set>
</class>


This is how I am trying to delete the Comment entity in my code:

Comment comment = dbClient.getComment(commentId);
comment.getBlog().getCommentSet().remove(comment);
comment.getUser().getCommentSet().remove(comment);
dbClient.deleteComment(commentId);

When debugging I have checked that after following code has been executed:

comment.getBlog().getCommentSet().remove(comment);
comment.getUser().getCommentSet().remove(comment);

The ref. from Blog and User to Comment has been removed.

Can anyone plz help me with this?


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

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.