Re: Refresh with transient objects (nHibernate + ActiveRecord)

2009-02-09 Thread Greg Burri

Hi,
Thanks for you answer.

I think it does work because I have a global session
(TransactionScope) and I want to flush it into the DB only if the user
hit the 'Save' button.
If I create a transaction for my edition dialog I have two solutions :

1) A inherited transaction
My loaded parent will be takes from the cache of my global
transaction.
If I add a child object to my parent and then call 'VoteRollBack' and
'Dispose' from my transaction the added child will not be removed from
my parent.

2) A new transaction
I can't load my parent because it only exists in my global transaction
cache which has not be yet flushed.
The two caches from both transaction are independent. So if I want to
load an object from a transaction, the other has to be flushed into
the DB. Is it right ?

I really don't understand how I can use nHibernate (and ActiveRecord)
with a real application :'(.
My approach is certainly wrong. I don't find a concrete example of an
application using nHibernate (and ActiveRecord).


Regards.

/Greg

On Jan 14, 2:49 pm, Markus Zywitza markus.zywi...@gmail.com wrote:
 This should work fine:

 1) You load parent and all associated childs in non-flushing sessionscope.
 2) More childs are added. No one calls save or something, so new
 childs are still transient.
 3) On Save-button pressed, call save on parent and cascade changes to child.
 4) On Cancel-button presses, discard the sessionscope and reload
 object in a new one.

 If you are using IDENTITY PKs, don't call save on childs, but rely on
 cascading instead! Saving them adds them to the DB instantly,
 regardless of flushing behaviour!

 -Markus

 2009/1/13 Greg Burri greg.bu...@gmail.com:



  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 :
          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 and
  ActiveRecord ?

  I have uploaded a little sample project here :
 http://www.gburri.org/bordel/ActiveRecordLifecycle.zip. 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

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Castle Project Users group.
To post to this group, send email to castle-project-users@googlegroups.com
To unsubscribe from this group, send email to 
castle-project-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~--~~~~--~~--~--~---



Re: Refresh with transient objects (nHibernate + ActiveRecord)

2009-02-09 Thread crios...@gmail.com

I think it's not really good idea to have long running transactions.
Instead use read-only sessionscopes (FlushAction.Never) and manually
Flush your session or reload entity from DB if you want to cancel the
operation.

On 9 фев, 14:01, Greg Burri greg.bu...@gmail.com wrote:
 I think it does work because I have a global session
 (TransactionScope)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Castle Project Users group.
To post to this group, send email to castle-project-users@googlegroups.com
To unsubscribe from this group, send email to 
castle-project-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~--~~~~--~~--~--~---



Re: Refresh with transient objects (nHibernate + ActiveRecord)

2009-01-14 Thread Markus Zywitza

This should work fine:

1) You load parent and all associated childs in non-flushing sessionscope.
2) More childs are added. No one calls save or something, so new
childs are still transient.
3) On Save-button pressed, call save on parent and cascade changes to child.
4) On Cancel-button presses, discard the sessionscope and reload
object in a new one.

If you are using IDENTITY PKs, don't call save on childs, but rely on
cascading instead! Saving them adds them to the DB instantly,
regardless of flushing behaviour!

-Markus

2009/1/13 Greg Burri greg.bu...@gmail.com:

 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 :
 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 and
 ActiveRecord ?

 I have uploaded a little sample project here :
 http://www.gburri.org/bordel/ActiveRecordLifecycle.zip. 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

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Castle Project Users group.
To post to this group, send email to castle-project-users@googlegroups.com
To unsubscribe from this group, send email to 
castle-project-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~--~~~~--~~--~--~---



Re: Refresh with transient objects (nHibernate + ActiveRecord)

2009-01-13 Thread Darius Damalakas
That's a very interesting problem you are addressing.

I will tell what we did in ou desktop app. Maybe this will give you an
overview of how different people use Castle.ActiveRecord and NHibernate to
achieve their goals. I don't say the below approach is brilliant or even
satisfactory, but it does reach it indeded purpose. So yes, business value
is delivered :)

Our app is performing all operations in memory + we use (already deprecated)
NHIbernate.Generics library so that both ends of association would contain
correct data.

Say we have this use case:

1) User want to create new parent object. A parent form is opened.
2) parent editing form has also a tab, where we display a list of all childs
it has
3) user wants to add new child, so he opens child editing form
4) user presses save on child editing form. form closes
5) parent form now shows one child in tab
6) user click on cancel button in parent form, and cancels all changes


What is happening under the hood in our app is:
1) we have a list of where we store all still to be applied operations on
the database.
So to this list we add single operation - save to databse our newly created
parent, but yet not commit this.
3) a new child object is created in memory (just plain object)
4) a relationship is made from childto parent.  for ex.  child.Parent =
myParent.   Now parent.ChildCollection contains one item, which is not yet
saved to databse.   This is happening with the help of NHibernate.Generics
All database operations from child editing form are appended to database
operations from parent editing form. Now there are two operations - both are
save to database. Firs operation saves parent, second - child.
6) when cancel is pressed, operations on databse are not applied. All
relationship changes made in memory are rolled backed. In this case,
child.Parent is set again to null.

This rollbacking makes possible to construct any-level of undo mechanism.
With this approach it is possible to work for one hour with an object and
then cancel any level of changes you made to the system.






2009/1/13 Greg Burri greg.bu...@gmail.com


 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 :
 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 and
 ActiveRecord ?

 I have uploaded a little sample project here :
 http://www.gburri.org/bordel/ActiveRecordLifecycle.zip. 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

 



-- 
Darius Damalakas

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Castle Project Users group.
To post to this group, send email to castle-project-users@googlegroups.com
To unsubscribe from this group, send email to 
castle-project-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~--~~~~--~~--~--~---