-->
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.  [ 5 posts ] 
Author Message
 Post subject: You cannot commit during a managed transaction!
PostPosted: Tue Nov 04, 2003 5:09 am 
Newbie

Joined: Tue Nov 04, 2003 4:48 am
Posts: 12
Location: Iran
I am tottaly new to hibernate and here is my code:

public void addUser(String name, Date date)
{
try {
Session session= sessionFactory.openSession();
Partner partner=new Partner();
partner.setName(name);
partner.setBirth(date);
Transaction transaction = session.beginTransaction();
session.save(partner);
transaction.commit();
session.close();
}catch(Exception ex){
logger.error(ex.toString());
}
- it is in a Session bean-
Every thing works fine and it even do commit to the database but gives an error:
net.sf.hibernate.TransactionException: Commit failed with SQL exception: : You cannot commit during a managed transaction!

What is wrong here?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 9:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Maybe not enough information but if this is running under a SLSB with CMT then its up to the container to start and commit the transaction. Rollback must be hinted at. You just open, flush and close the session.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 6:18 am 
Newbie

Joined: Tue Nov 04, 2003 4:48 am
Posts: 12
Location: Iran
It is running unser jboss and the mentioned code is in a stateless session bean. and here is my hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

<session-factory>

<property name="connection.datasource">java:/shabwareDS</property>
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>

<!-- Mapping files -->
<mapping resource="org/shabdiz/shabware/entity/PartnerValue.hbm.xml"/>

</session-factory>

</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 9:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
But what david was pointing out that it is more a question of whether your ejb is under CMT control. In other words, are you specifying "Container" as the transaction attribute in the ejb deployment descriptor? If so, as per ejb specs, it is not legal to manually attempt to "tinker" with the JTA transaction started by the container or any of the connections under the control of the container (which is exactly what the transaction.commit() in your code is doing).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 1:35 am 
Newbie

Joined: Tue Nov 04, 2003 4:48 am
Posts: 12
Location: Iran
You are right! :"> i can't believe that I was such a fool!
Thanks a lot.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.