-->
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.  [ 5 posts ] 
Author Message
 Post subject: saveOrUpdate with unsaved-value=undefined performance
PostPosted: Tue Apr 12, 2005 6:46 am 
Beginner
Beginner

Joined: Sat Jan 01, 2005 12:18 pm
Posts: 23
Hibernate version: 3

I use assigned ids in my mappings and if I want to use saveOrUpdate I have to add unsaved-value=undefined

The result seems to be that Hibernate generates an SQL select statement to determine if the dataset exists and then to perform either an update or an insert depending on the select statement.

Wouldn't it be better to make only an update (which actually includes a where clause to determine the existence of the dataset) and if that fails to create an insert? That would reduce an extra statement with a probability of 0.5 (depending on your data) with the result, also depending on your data, in a performance gain.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 8:48 am 
Beginner
Beginner

Joined: Thu Mar 24, 2005 5:21 pm
Posts: 21
If you want to avoid the extra SELECT, you can define a version or time-stamp property with an unsaved value (in combination with the assigned primary key). Of course this won't work if you are working with a legacy database whose schema you can't change...
HTH
Satish


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 8:50 am 
Beginner
Beginner

Joined: Thu Mar 24, 2005 5:21 pm
Posts: 21
mm - not sure I phrased that particularly well. Trying again:
If you want to use assigned primary keys and wish to avoid the extra SELECT, you can define a version or time-stamp property with an unsaved value. Of course this won't work if you are working with a legacy database whose schema you can't change...
HTH
Satish


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 9:30 am 
Beginner
Beginner

Joined: Sat Jan 01, 2005 12:18 pm
Posts: 23
I could do that but it was more a question "why" Hibernate makes an extra select statement which costs extra time instead of trying to make and update which would reduce time in case if a dataset with the given id exists if not then you have lost nothing and it just makes an insert.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 2:34 pm 
Regular
Regular

Joined: Thu Nov 13, 2003 2:55 am
Posts: 71
Location: Sweden
Have a look at the Interceptor in section 16.4: http://www.hibernate.org/hib_docs/refer ... child.html


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