Shouldn't nHibernate ISession.BeginTransaction() fail when a transaction
is already open?
I know these kinds of questions can lead to flame wars. Personally I'm a
huge fan of nHibernate and I realize no ORM is perfect. I'm just trying to
determine if there's a good reason for this I'm unaware of or if it's a
design flaw that exists because changing it would break existing code.
Here's the behavior I'm describing:
Assuming I have an existing ISession named session shouldn't the following
code throw an exception on the third line due to the fact that nHibernate
does not support nested transactions.
ITransaction tx = null;
tx = session.BeginTransaction();
tx = session.BeginTransaction();
If we assume that there are no other transactions open on the current
thread the first call to BeginTransaction() does indeed begin a
transaction. However the second merely returns the existing transaction.
It gives the impression that nested transactions are supported. Is this
bad nomenclature?
Would it make more sense to create two methods? One for grabbing an
existing transaction or creating one if none exists in situations where
the developer doesn't care and another method that specifically creates
new transactions and fails when it cannot?
This question is about nHibernate but perhaps this applies to Hibernate as
well.
No comments:
Post a Comment