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.  [ 1 post ] 
Author Message
 Post subject: Defer session.Save() and session.Delete()
PostPosted: Sat Jul 21, 2007 8:04 pm 
Beginner
Beginner

Joined: Sat Jul 21, 2007 3:56 pm
Posts: 27
Basically what I'm trying to accomplish is to configure the NHibernate session as a disconnected unit-of-work in a two-tier smart client architecture.

The session should only temporarily connect to the database when data is needed from the database and any changes (i.e. the insert/update/delete statements) should only be committed to the database at the end of the unit-of-work.

Now, if I put the session's flushmode to Commit, I can see that the modifications to the persistent objects and even the creation of child objects of a certain persistent object are nicely cached within the session until the session.Commit() is called. I guess what I am experiencing here is the persistence-by-reachability pattern.

But if I want to create a new root object (one that I cannot just add to the collection of a persistent object) I explicitly have to call the session.Save() method for it. This will either generate an insert statement (if the id generator is "identity") or retrieve the sequence's nextval (if the id generator is "sequence"). Even though the latter doesn't actually modify the database, it requires to connect to the database.

I also noticed that removing objects by calling the session.Delete() method also require that the session is connected in some scenarios.

Unfortunately, I have not been able yet to force the session.Save() and session.Delete() methods to defer their sql statement until the commit is called. Therefore I am thinking of subclassing the NHibernate provided session to defer the calls to these methods until the session.Commit() is called.

Does anyone know how to configure NHibernate to provide a custom session?

Or maybe there is an easier way to accomplish what I'm trying to do?

You can find my code here: http://www.paarden.be/NHibernate/Sol_PaardenConfigurator.zip

Thanks in advance,

Tolomaüs.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.