-->
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: save() method first make insert and then update call why?
PostPosted: Tue May 17, 2005 7:45 pm 
Newbie

Joined: Tue May 17, 2005 7:32 pm
Posts: 7
I am using session.save() method to insert data.

I noticed that hibernate first call an insert statement and then an update statement for each save() call. I am not sure why hibernate is making an update call to database.

[b]My question is can i disable this update call and just have an insert call to database. I feel this update is reducing my application performance. I have around 50,000 rows to be inserted everyday.[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 5:06 am 
Newbie

Joined: Wed May 18, 2005 4:50 am
Posts: 18
I think that you should call "save" only after setting all the attributes of the object then only an "insert" should be generated. If you modify any attributes of the object after "save" in the same transaction you will get an "insert" followed by an "update".

I am new to Hibernate, but I think this is the "normal" behavior.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 11:10 am 
Newbie

Joined: Tue May 17, 2005 7:32 pm
Posts: 7
I am not making any change to the object. In fact i inserted some System.out in my code just before the call to save() method and just after it.

And in between i saw two calls to DB one is insert and then an update. even though i am not making any chnage to my object


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 11:18 am 
Newbie

Joined: Tue May 17, 2005 7:32 pm
Posts: 7
I am not making any change to the object. In fact i inserted some System.out in my code just before the call to save() method and just after it.

And in between i saw two calls to DB one is insert and then an update. even though i am not making any chnage to my object


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 11:58 am 
Newbie

Joined: Tue May 17, 2005 7:32 pm
Posts: 7
Ok,

I got the problem. You were right. The object state is being changed. I have a column name update_date in the table. In object instance i pass "new Date()" in the "get" method.

Now this actually changes when the data is being commited to the DB. So it first make an insert to the DB and then makes an update to update the chnaged value of update_date which would change because of some micro seconds difference.

But then how do i insert an update_date to my column which would be current date without this update being called. I am not really bothered about the exact time being inserted.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 4:36 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
gargrishi wrote:
Ok,

I got the problem. You were right. The object state is being changed. I have a column name update_date in the table. In object instance i pass "new Date()" in the "get" method.

Now this actually changes when the data is being commited to the DB. So it first make an insert to the DB and then makes an update to update the chnaged value of update_date which would change because of some micro seconds difference.

But then how do i insert an update_date to my column which would be current date without this update being called. I am not really bothered about the exact time being inserted.


look at the <timestamp> mapping in hibernate if this is a timeLastUpdated type of attribute.


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.