-->
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: problem deleting collections
PostPosted: Tue May 08, 2007 12:51 am 
Newbie

Joined: Tue May 08, 2007 12:25 am
Posts: 18
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0
Mapping documents:

<class name="recipe.Recipe" table="recipes">
<id name="id" column="ID">
<generator class="identity"/>

</id>
<property name="name" column="recipe_name" />


<set name="tags" cascade="all,delete-orphan" inverse="true">
<key column="recipe_id" not-null="true" />
<one-to-many class="recipe.Tag" />
</set>
</class>

<class name="com.familyoven.recipe.Tag" table="recipes_tags">
<id name="id" column="id">
<generator class="identity"/>
</id>
<many-to-one name="recipe" foreign-key="recipe_id" column="recipe_id" class="recipe.Recipe"/>
<property name="name" column="name" />
</class>
Code between sessionFactory.openSession() and session.close():
recipe.getTags().clear();

Full stack trace of any exception that occurs:

Name and version of the database you are using:
MySQL 5.0
The generated SQL (show_sql=true):
delete from recipes_tags where id=?
delete from recipes_tags where id=?
delete from recipes_tags where id=?

The problem is, that hibernate issues 3 delete statements instead of one statement based on the foreign key. IE:
delete from recipes_tags where recipe_id=?

what can I do to make it issue one statement.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 08, 2007 1:22 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi imosquer,

Hibernate works on object. So recipe.getTags().clear() code actually remove three object in your case. So corresponding to Hibernate it perform three delete statement

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 08, 2007 1:50 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
Hibernate supports "one-shot-delete" for collections of value type only.
You can have a look at,
http://forum.hibernate.org/viewtopic.php?t=945057
http://forum.hibernate.org/viewtopic.php?t=934392
http://forum.hibernate.org/viewtopic.php?t=973922

-----------------------------------------
Rate the reply if you find it helpful


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.