Indeed, they have different responsabilities.
However, if a transaction object would not be visible outside a session that would not be problematic.
As far as I know, you cannot have multiple transactions that are 'alive' at the same time, if the share the same connection.
If you use a session, without using a transaction, it would also not be a problem: the transaction object is just encapsulated into the session object.
I think, it will keep the api simpler if these 2 objects 'were put in one class'.
The Session object would then have a StartTransaction method (like it has now), but it would also have a commit and rollback transaction.
This would not be a problem if 'paralel transactions' are not supported. However, if you have a database, which allows nested transactions, it can be a problem.
(AFAIK, the SqlClient and OleDb providers do not allow you to start a transaction on a connection, if another transaction was already started on that connection).
note: I'm not critizizing the design of hibernate; I'm just thinking and wondering.
|