I have a Sybase 11.9.2 connection pooled (DBCP 1.1 RC1) datasource set up and bound to JNDI (completely outside of Hibernate), with autocommit = false.
Outside of Hibernate (by looking up JNDI to get the Datasource, and then getting a connection directly from the datsdatasource), I can see that autocommit = false (correct), and more importantly, that @@TRANCHAINED = 1 and @@trancount = 1 (ie, autocommit is false, so a transaction has been opened via Sybase "chained mode"), which is exactly what I'd expect.
However, when I try to use this datasource using Hibernate, I get errors related to the fact that chained mode is OFF (when it should be still ON). The transaction that *should* be open (because autocommit is off) has been incorrectly closed somewhere (either using a commit/rollback, or via connection.setAutoCommit(true) ).
Does anyone know why / when this is happening?? I suspect Hibernate is doing something funny with the connection before it uses it, but having looked at the Hibernate code, I can't see it.
My config:
I have turned *off* connection pooling in Hibernate (to prevent it conflicting with DBCP), and I am using the JDBCTransactionFactory instead of the JTATransactionFactory. I am also using the Hibernate Transaction API rather than the J2EE UserTransaction variety.
My hibernate.properties:
Code:
hibernate.show_sql=false
hibernate.use_outer_join=false
hibernate.connection.datasource=java:clientdb-ds
hibernate.connection.isolation=1
hibernate.dialect=net.sf.hibernate.dialect.SybaseDialect
jta.UserTransaction=UserTransaction
connection.mapping.files=com/kbcam/core/entity/NextId.hbm.xml
hibernate.transaction.factory_class=net.sf.hibernate.transaction.JDBCTransactionFactory
hibernate.connection.pool_size=0
The sql I am using to see that the problem is definitely with the connections opened by Hibernate (and not with the connections opened outside of Hibernate) is the following:
Code:
select spid, cmd, tran_name
from master..sysprocesses
where dbid = db_id ()
and suid = suser_id ("myusername")
and spid <> @@spid
(gets processes for "myusername" on the current database). Note that if a tran is open on the connection, the "tran_name" value will be NOT null. Null implies that there is NO transaction open, which is what I am seeing using Hibernate on the same Datasource.