[junit] 2008-02-01 16:08:11,585 VOSPACE DEBUG Transaction failed in ServiceImpl.copyURLToContent() [could not initialize proxy - the owning Session was closed]
Enabled debug logging for the Hibernate libraries and found this :
[junit] 2008-02-01 16:08:11,152 VOSPACE DEBUG committed JDBC Connection
[junit] 2008-02-01 16:08:11,152 VOSPACE DEBUG after transaction completion
[junit] 2008-02-01 16:08:11,152 VOSPACE DEBUG aggressively releasing JDBC connection
[junit] 2008-02-01 16:08:11,152 VOSPACE DEBUG releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
[junit] 2008-02-01 16:08:11,152 VOSPACE DEBUG returning connection to pool, pool size: 1
It looked like Hibernate was closing the Session and JDBC Connection after every Transaction.
Which mean that my in-memory objects were stale, and no longer connected to a Hibernate Session.
I originally thought that you could use more than one Transaction within a Hibernate Session.
In fact, having spent a few hours on Google it turns out that that is indeed the way you should use Hibernate.
"Can I use two transactions in one Session?" "Yes, this is actually a better implementation of this pattern ...."Just that it isn't configured to do that by default. The standard 'out of the box' system is configuration with a connection pool of 1, and 'aggressively' releases JDBC connections at the end of every Transaction.
"The first two implementations provide a 'one session - one database transaction' programming model, also known and used as session-per-request. The beginning and end of a Hibernate session is defined by the duration of a database transaction."To make it scale to an enterprise level system, you need to set the connection release mode
hibernate.connection.release_mode = auto (default) | on_close | after_transaction | after_statement
add a 3rd party connection pool, and handle the Session management yourself.
![]() |
Click here for the AstroGrid Service Web |
This is the AstroGrid Development Wiki |
|