hi all, i need to use a session per-request pattern in a web
enviroinment (pure asp.net 2.0) but i have same doubts.
in same example i see that in the http module there's only the bind/
unbind of the session and the transaction are explicity managed by the
user every time that it's needed.
in other examples (as uNhAddIns.Web.NHSessionWebModule) the http
module begins and commit/rollback a transaction at begin/end of http
request and user code is samething as
void ExecuteAction(ItemA a, ItemB b)
{
//internally use the context session returned by the
sessionfactory
daoA.MakePersistent(a);
daoB.MakePersistent(b);
}
but in this case if daoA throws an exception i cannot understand how
the transaction is rollback witouh an explicit try/catch, becouse in
the end request i cannot know if data are valid to be commited or if
they must be rollback.
a solution is to explicity add the transaction management also in the
ExecuteAction method
void ExecuteAction(ItemA a, ItemB b)
{
try
{
daoA.MakePersistent(a);
daoB.MakePErsistent(b);
GetCurrentSession().Transaction.Commit();
}
catch(Exception)
{
GetCurrentSession().Transaction.Rollback():
}
}
but in this case if after that methods there's same other access to
the db (for example for data rendering) there's not an explicit
transaction management (and i read that is a bad pattern to use the
isession without encapsulate the usage inside a itransaction)
so my final idea is to use
void ExecuteAction(ItemA a, ItemB b)
{
try
{
daoA.MakePersistent(a);
daoB.MakePErsistent(b);
GetCurrentSession().Transaction.Commit();
}
catch(Exception)
{
GetCurrentSession().Transaction.Rollback():
}
GetCurrentSession().BeginTransaction();
}
any comments?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---