-->
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.  [ 3 posts ] 
Author Message
 Post subject: deleted object would be re-saved by cascade
PostPosted: Sat Feb 12, 2005 10:28 am 
Newbie

Joined: Thu Feb 03, 2005 11:36 am
Posts: 11
I get this error when trying to delete a Message or a Comment.
A Message is associated to one Category, and a Comment is a associated to one Message.

Does this error mean that I need to work on the Category collection to delete a Message and to the Message collection to delete a Comment ?
In that case it seems strange to me... If I had one Keyword object associated with a Message how should I do ? Remove the Message from Category or from Message?

Of course, I'm new to Hibernate ;-)

Thank for your help

Hibernate version:
2.1
Mapping documents:
<hibernate-mapping package="hibgen">

<class name="hibgen.Message" table="message">
<id name="id" type="long" column="id">
<generator class="vm"/>
</id>
<property name="title" column="title" type="string" not-null="false" length="255" />
<property name="content" column="content" type="text" not-null="false"/>
<property name="datecreated" column="datecreated" type="date" not-null="false"/>
<property name="datemodified" column="datemodified" type="date"
not-null="false"/>
<many-to-one name="category" column="categoryid" class="hibgen.Category" not-null="true"/>
<set name="comments" inverse="true" cascade="all" order-by="datecreated">
<key column="messageid"/>
<one-to-many class="Comment"/>
</set>
</class>

<!-- Commentaires associés à message -->
<class name="hibgen.Comment" table="comment">
<id name="id" type="long" column="id">
<generator class="vm"/>
</id>
<property name="content" column="content" type="text" not-null="false"/>
<property name="name" column="name" type="string" length="64" not-null="false"/>
<property name="email" column="email" type="string" length="64" not-null="false"/>
<property name="uri" column="uri" type="string" length="128" not-null="false"/>
<property name="datecreated" column="datecreated" type="timestamp" not-null="false"/>
<many-to-one name="message" column="messageid" class="hibgen.Message" not-null="true"/>
</class>

<!-- Catégories de messages -->
<class name="hibgen.Category" table="category">
<id name="id" type="long" column="id">
<generator class="vm"/>
</id>
<property name="title" column="title" type="string" length="64" not-null="false"/>
<set name="messages" inverse="true" cascade="all">
<key column="categoryid"/>
<one-to-many class="Message"/>
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 09, 2005 8:01 am 
Newbie

Joined: Wed Jan 26, 2005 10:17 pm
Posts: 8
Aboulafia,

This error means that the object you're tying to delete, still exists in some association of another object.
If you do not remove the object-to-be-deleted form all association-collections, the object would get saved/inserted again when the "parent" object is saved/udated.

So just remove the object-to-be-deleted from the collection first,
( something like category.getSetOfMessages().remove( object-to-be-deleted ),
then call session.delete(object).

Hope this helps.

[]'s


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 11:16 am 
Newbie

Joined: Wed Apr 20, 2005 10:42 am
Posts: 1
bastiaanlos wrote:
Aboulafia,
This error means that the object you're tying to delete, still exists in some association of another object.
If you do not remove the object-to-be-deleted form all association-collections, the object would get saved/inserted again when the "parent" object is saved/udated.

So just remove the object-to-be-deleted from the collection first,
( something like category.getSetOfMessages().remove( object-to-be-deleted ),
then call session.delete(object).
[]'s


Unfortunately this method will make Hibernate load the entire collection of Message objects into memory. This is not performant or even possible with very large collections.
We are currently optimising a system where the collections have several thousand entries resulting in minutes of waiting for our users.
On the long term, we are expecting collections with up to 100,000 elements.
The above solution will not even be theoretically possible for this system.

Our solution to adding to a many-to-one collection has been proposed earlier on this forum. The solution is to only set the non-inverse side and don't call collection.add() on the inverse side of the mapping.

BUT: we need a method for removing from a collection. We hope to find a way of doing this without using raw SQL.

Good ideas, anyone?

Best regards

Kim Oechsle


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.