Hibernate session / transaction design


Hibernate session / transaction design



I'm trying to figure out how to best use Sessions in (N)Hibernate. I have a C# remoting object (MarshalByRefObject) which gets consumed by an ASP.NET client. Currently my remoting class opens up one Session instance in the constructor and uses that one for all transactions. Is this a good idea? And would I need a finalizer for the remote object where session.Dipose() gets called?

Each client request opens a new transaction. Now my database access looks generally like this:

ITransaction transaction = this.session.BeginTransaction(); try { // perfrom nhibernate query transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); this.session.Flush(); } 

and then I often return the retrieved database object to the client. Is this a valid way to handle this? Should I use the transaction object in a using block or call Dispose() on it? Is the session.Flush() needed after the rollback?

Also sometimes I have a problem when binding a returned collection to a GridView. It throws a exception stating that a binding property of a certain object is not valid. Is this related to hibernate returning proxy objects? And why are the collected objects by hibernate within one query a mixture of "real" and proxy objects?

Thanks!




How can Hibernate map the SQL data-type nvarchar(max)?

1:



How can I find the error when Tomcat fails to start my Spring/Hibernate web application?


Javax package and simple java application with spring hibernate


76 out of 100 based on 56 user ratings 1006 reviews