mate wrote:
I'm no expert here either, but spontaneously it seems Hibernate does wrong in not returning the connection after the commit.
emmanuel wrote:
It does make perfect sense a non JTA environment.
Yes. But this is a JTA environment. Maybe this should be managed differently there?
mate wrote:
How is the TransactionManager/Transaction supposed to know somebody is already holding a resource (i.e. a connection) that should be enlisted?
Should the DataSource keep track of all connections provided to a Thread, and if that Thread starts a transaction enlist all those connections. (I cannot remember any such thing in the JTA specs).
emmanuel wrote:
I would say yes, the DB keep track of all connections provided to a thread and to return the *same* connection while requestion the same DS. While not mandatory, I don't know any app server not doing this.
Firstly, this is assuming the connection has been "closed" or "returned to the pool". If you open two connections at once (for example by mixing Hibernate and pure JDBC) you get - and should of course get - two different connections.
Secondly, Resin (2.1.x) guarantees to return the same connection
only if within a (JTA) transaction. If no (JTA) transaction is started, the thread will get the first available connection from the pool just as when the thread requests a connection the first time.
I would actually expect this to be common behaviour. AFAIK most application servers also provide a thread pool, so that threads are shared among consecutive requests. If the connections in the connection pool were always (whether in a transaction or not) associated with a (pooled) thread - so that the threads get the same connection from the connection pool every time, over multiple requests - the connection pool would be rather useless.
emmanuel wrote:
What you can do is disconnect() and reconnect() the session to get a new connection from the DS
Yes that works.
Though this cannot be such a unique scenario, can it.
How is everybody else solving this???