-->
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: saveOrUpdate only if necessary
PostPosted: Wed Apr 09, 2008 8:30 pm 
Newbie

Joined: Sat Dec 30, 2006 3:07 pm
Posts: 16
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.6

Mapping documents:
annotations 3.3.0

Name and version of the database you are using:
mysql 5.0



Is there a way to configure hibernate so that a save to the database happens only if it is necessary.

I have a process that retrieves xml data from a third party.
loads an object from the database that may have been previously instantiated.
sets the fields with the new data from the xml file.
and then saves the object.

I assumed that if the object did not change that hibernate would not issue a save to the database, but it does.

Is there a way to configure hibernate so that the save occurs only if one of the fields in the object is different?


Thanks

Kal


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 12:25 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
You could use a manual flush mode for the session. By setting it to manual instead of auto, you can do the fushing whenever you want. If you dont set it to manual, hibernate will automatically save the update state of the object in the session to the database.


Code while getting the session
Code:
Session session = sessionFactory.getCurrentSession();
session.setFlushMode(FlushMode.MANUAL);



Manual flushing while save

Code:
session.save(someObject);
session.flush();

_________________
Sukirtha


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.