-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: HibernateContext, TableGenerator and AutoCommit problem
PostPosted: Mon Jan 17, 2005 6:54 pm 
Newbie

Joined: Mon Jan 17, 2005 5:46 pm
Posts: 1
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!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 7:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
As the documentation clearly states, you can not use hilo in a managed environment.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 7:06 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There is a way but you have to implement you own id generator. Have a look at
http://cvs.sourceforge.net/viewcvs.py/jboss/jboss-ejb3/src/main/org/jboss/ejb3/entity/JTATableIdGenerator.java?rev=1.1&view=auto

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 25, 2005 10:42 pm 
Regular
Regular

Joined: Thu Aug 26, 2004 9:23 pm
Posts: 71
Here is something strange. I am experiencing the exact same problem. However, I am not using hilo for any of my object.

Hibernate Version: 2.1.7
Jboss Version: 4.0.1

Is there any reason why hibernate would use hilo when I'm clearly using a sequence? Here is my mapping file for the object I'm attempting to save. (Sorry for the Xdoclet garbage)

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping
>
<class
name="com.avaloninc.account.data.Group"
table="groups"
lazy="true"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>
<cache usage="transactional" />

<id
name="id"
column="group_id"
type="java.lang.Long"
access="property"
>
<generator class="native">
<param name="sequence">group_seq</param>
</generator>
</id>

<property
name="created"
type="java.util.Date"
update="false"
insert="true"
access="net.sf.hibernate.property.DirectPropertyAccessor"
column="created"
not-null="true"
/>

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="name"
not-null="true"
/>

<property
name="defaultGroup"
type="java.lang.Boolean"
update="true"
insert="true"
access="property"
column="default_group"
not-null="true"
/>

<property
name="disabled"
type="boolean"
update="true"
insert="true"
access="property"
column="disabled"
not-null="true"
/>

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 26, 2005 1:21 pm 
Regular
Regular

Joined: Thu Aug 26, 2004 9:23 pm
Posts: 71
Nevermind....found the problem. It appeared to be because of a faulty custom dialect I was using. :)

Mike


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 26, 2005 1:37 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
BTW, we've implemented the JTA-enabled hilo generator in H3beta2

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.