Hi,
here's the configuration I'm working with:
Hibernate version: 2
JBoss version: 4.0
Here's the problem: I get the hibernate session from org.jboss.hibernate.session.HibernateContext inside a Stateless Session Bean. see:
http://www.jboss.org/wiki/Wiki.jsp?page=JBossHibernate. The session bean tries to save an object using hibernate. Upon calling session.save(persistentObject); I get the following exception:
Caused by: java.sql.SQLException: You cannot set autocommit during a managed transaction!
at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.setJdbcAutoCommit(BaseWrapperManagedConnection.java:442)
at org.jboss.resource.adapter.jdbc.WrappedConnection.setAutoCommit(WrappedConnection.java:432)
at net.sf.hibernate.id.TableGenerator.generate(TableGenerator.java:85)
at net.sf.hibernate.id.TableHiLoGenerator.generate(TableHiLoGenerator.java:59)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:776)
Upon reading the source code, turns out that TableGenerator.generate() calls conn.setAutoCommit(false); to ensure that the generated id is unique across the transaction context. However, this a container managed transaction and so the jboss managedConnection wrapper (BaseWrapperManageConnection) throws an exception when setAutoCommit(false) is called.
How can I resolve this problem? Any help would be much appreciated!