-->
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: Does session commit flush the entire ISession?
PostPosted: Mon Sep 08, 2008 5:02 pm 
Newbie

Joined: Sat Sep 06, 2008 4:55 pm
Posts: 5
Hi, I'm new to hibernate and have designed my application around the thought that hibernate is only going to commit dirty data when I tell it to (flush/SaveOrUpdate). In the scenario below, I want it to save the changes made to itemB, but not save the changes made to itemA. I have recently read that commit calls flush, which means my itemA would be saved even though I don't want it to be. Is there another way I should be doing this? Or do I have to wait until the session is closed before I add new subitems to an object. Perhaps if I change the flush mode?

Sorry, I'm a bit of a newb


Code between sessionFactory.openSession() and session.close():

ISession session = sessionFactory.openSession();

MyPersistantItem itemB = m_session.Get(type, 2);
itemB.Name = "Changed";

MyPersistantItem itemA = m_session.Get(type, 1);
itemA.SubItems(new MyPersistantItem2());
itemA.Name = "Also changed";

ITransaction tx=null;
try
{
tx = session.BeginTransaction();
session.SaveOrUpdate(itemB);
tx.Commit();
}
catch (Exception ex)
{
if (tx!=null) tx.Rollback();
throw ex;
}

session.close();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 8:27 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Once an entity has 'touched' the Session, Hibernate will handle updating the object. If you don't want this, you can always call an evict, which will detach the entity from the Hibernate Session.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.