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();
|