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.  [ 6 posts ] 
Author Message
 Post subject: delete(String query) vs. delete(Object object)
PostPosted: Tue Dec 14, 2004 9:01 am 
Newbie

Joined: Mon Dec 13, 2004 11:40 am
Posts: 11
i was curious,
if i want to delete one object..
is one method better than the other in terms of performance?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 10:53 am 
Regular
Regular

Joined: Thu Oct 07, 2004 4:45 pm
Posts: 92
I believe they are the same, but not 100% sure. However, another factor to consider is that delete(String) essentially defeats optimistic locking.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 11:00 am 
Newbie

Joined: Mon Dec 13, 2004 11:40 am
Posts: 11
Thank you very much for your comment,

can you please elaborate about the optimistic locking.

btw, is the same number of sql statements are being executed?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 10:13 pm 
Regular
Regular

Joined: Thu Oct 07, 2004 4:45 pm
Posts: 92
Optimistic locking is covered in the reference manual:

http://www.hibernate.org/hib_docs/refer ... optimistic

In this case, it prevents you from "accidentally" deleting an object that has been changed in another transaction. Depending on your use case, it may or may not be a concern.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 4:19 am 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
rhasselbaum wrote:
I believe they are the same, but not 100% sure. However, another factor to consider is that delete(String) essentially defeats optimistic locking.


I'm not sure if this is correct. As far as I am aware delete( String ) is roughly the same as doing

Code:
List results = session.find( string );
for ( Object results : results )
{
    session.delete( result );
}


So the locking check will be done in the delete as the object has been loaded.

To answer the original question, delete( Object ) will generally be faster as it does not query the database.[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 12:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
So the locking check will be done in the delete as the object has been loaded.


But the point is that the entity was just loaded; the versioning data will always be exactly what it is in the database at this time, not the versioning data as of the time the user read the object(s) initially.

If this is a concern, then the bulk delete approach will not work as it essentially circumvents the optimistic lock.


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