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: session.delete issue /Hibernate & Spring
PostPosted: Wed Apr 18, 2007 8:09 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1.2
Mapping documents:

Code between sessionFactory.openSession() and session.close():
List<Batch> list = getHibernateTemplate().find(
"from Batch batch where creationDate < ?", new Object[]{archivedDate});
System.out.println("*********** finished list with size: " + list.size());


for(Batch b : list) {
System.err.println("*** deleting gbatch with id:" + b.getId());
getHibernateTemplate().delete(b);


}
Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Hibernate: select 0_.batchId as Ba6_1_, message0_.id as id1_, message0_.seq_idx as seq7_1_, message0_.id as id36_0_, message0_.ISIN as ISIN36_0_, message0_.productId as productId36_0_, message0_.rawXml as xml36_0_, message0_.processDate as processD5_36_0_, messagebond0_.sierraBatchId as sierraBa6_36_0_ from Message sierrabond0_ where message0_.BatchId=?


Hi,
I am using Hibernate via Spring (HibernateTemplate) which ultimately calls Session.delete in order to delete my objects..

form the output hibernate gave me (listed above) it turns out that hibernate does a select statement to find all Message childrens before it deletes the Batch object.

I was wondering why hibernate does not do a "delete from Message where message.batchId = Batch.batchId) statement.....

is it because in the mapping document i have specified
Code:
<list name="messages" lazy="true" cascade="all,delete-orphan" inverse="true">
<key column="batchId"/>
<index column="seq_idx"/>
<one-to-many class="Message"/>
</list>


?

or instead is a standard Hib behaviour to do a select statement to retrieve all children of an object before deleting it?


I have read hibernate docs, and they say that session.delete has been deprecated, and to use SQL instead......
shall i go that way? i thought that it was simpler and easier to let hibernate handle automatically the deletion of children when a parent is deleted, but it turns out that the select statement before every deleetion will slow down my app big time, especially when i have large number of chilidrens...

regards
marco



thanks in advance and regards
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 10:07 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I think the correct and much quicker delete statements are an issue for a future release. For now, if I'm deleting entire objects, I find it quicker to write my own.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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.