Using JBoss 3.0.4, the Apple OS X JDK 1.4DP6 and Postgres 7.2.2 it is impossible to persist objects using Hibernate (beta4). When using code similar to:

Person p = new Person();
Session sess = Hibernate.openSession();
sess.save( p );  // Exception thrown here
// Close session properly.

The following SQL exception is thrown:

java.sql.SQLException: You cannot commit with autocommit set!

This is ultimately caused by the HiLoGenerator while trying to set the persisted object's ID. If I try the same sort of thing with a Transaction:

Person p = new Person();
Session sess = Hibernate.openSession();
Transaction tx = sess.beginTransaction();
sess.save( p );  // Exception thrown here
tx.commit();
// Close session properly

The exception:

java.sql.SQLException: You cannot commit during a managed transaction!

is thrown. This is again caused by the HiLoGenerator.

As I had not seen this behaviour under previous versions of JBoss, I posted to the JBoss user list asking if anyone else had seen this problem. David Jencks, one of the JBoss developers, replied that:

"Autocommit on is required by the jca spec, and should have been the case
for 3.0 versions as well. You should endevour to make the transactions be
controlled by the jboss tm/jta/cmt etc."


Which fits with my error messages because I obtain my datasource from the JNDI (java:/DefaultDS, if that helps) The problem is that the HiLoGenerator (which my classes use) commits the changes that it has made to the underlying Hi/Lo table by calling Connection.commit() (line 131 in HiLoGenerator.java, I think) rather than using a transaction, which would work. Are there any known work-arounds to this problem other than generating the IDs myself? Should I mark it as a bug on the sourceforge pages?

Regards,

Simon



-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size! http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel




Reply via email to