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: Refresh with transient objects (nHibernate + ActiveRecord)
PostPosted: Wed Dec 17, 2008 11:14 am 
Newbie

Joined: Wed May 14, 2008 4:18 am
Posts: 1
Hi,
I use nHibernate with ActiveRecord in a such manner :
  • I have a global session of type 'TransactionScope'
  • When the user want to save his work his click on "file -> save" of the application menu. This action will execute a such code :
    Code:
    globalSession.VoteCommit();
       globalSession.Dispose();
       globalSession = new TransactionScope();

Basically I have a dialog to edit an object 'p' of class 'Parent' which owns some objects 'c' of class 'Child'. Both of theses classes deriving from 'ActiveRecordLinqBase'.

When the user choose 'Cancel' from the dialog after editing some values of 'a' and adding or removing some B objects I want to reverse theses changes (that is remove 'Child' objects that was added and add removed 'Child' objects).

(Case 1) If I use the method "p.Refresh()" there will be an exception like "No row with the given identifier exists[Child#0]" in the case the user added some 'c'.
(Case 2) If I use a transaction with "p.SaveAndFlush()" + "t.VoteRollBack()" + "t.Dispose()" then this error will be throwed : "Illegal attempt to associate a collection with two open sessions" (for the same case above, where a 'b' is added).

Is my approach is good ? Or it's a misusing of nHibernate ?

I have uploaded a little sample project here. If you want to run it you need PostgreSQL or change the 'app.config'.
This sample will create a parent and some children attached to it at launch.
You can edit the 'Parent' object and change its state with the button "Change state" and try to undo the modifications with "Cancel".

Here are some additional information about my configuration :

nHibernate version: 2.1.0.1001
Active record version: 1.0.3.0
Database: PostgreSQL 8.3

Thanks in advance.

/Greg


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.