-->
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: EJB 3 and Hibernate Transactions (SUPPORTS)
PostPosted: Wed Apr 04, 2007 3:26 am 
Newbie

Joined: Fri Dec 29, 2006 1:17 am
Posts: 3
Hibernate version:
3.2

Full stack trace of any exception that occurs:

org.hibernate.HibernateException: Unable to locate current JTA transaction
at org.hibernate.context.JTASessionContext.currentSession(JTASessionCont
ext.java:61)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactor
yImpl.java:542)
at org.jboss.hibernate.session.HibernateContext.getSession(HibernateCont
ext.java:94)

Name and version of the database you are using:
Oracle 9.2.0.6


Using EJB 3 Session Bean and with following attributes. I have set the Transcation Attribute Type to SUPPORTS for EJB.

========================================
@Stateless
@Remote(TestManager.class)
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@RolesAllowed("TestUser")
@SecurityDomain("TestSecurity")
@RemoteBinding(jndiBinding="TestManager")
public class TestSBean extends SessionBean implements TestManager
========================================


In one of the method implementation I am using

HibernateContext.getSession("java:/ZafeSessionFactory");

to get the Session and it throw above error.

org.hibernate.HibernateException: Unable to locate current JTA transaction


Here's the hibernate-service.xml

<server>
<mbean code="org.jboss.hibernate.jmx.Hibernate" name="jboss.har:service=ZafeHibernate">
<attribute name="DatasourceName">java:/ZafeDS</attribute>
<attribute name="Dialect">org.hibernate.dialect.Oracle9Dialect</attribute>
<attribute name="SessionFactoryName">java:/ZafeSessionFactory</attribute>
<attribute name="MaxFetchDepth">3</attribute>
<attribute name="ShowSqlEnabled">false</attribute>
<attribute name="Hbm2ddlAuto">update</attribute>
</mbean>
</server>

Any idea why?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 7:03 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
According to the doc (http://www.hibernate.org/hib_docs/v3/re ... ansactions) you just have to do :
Code:
// CMT idiom
Session sess = factory.getCurrentSession();

// do some work

in a managed environment

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject: Why supports?
PostPosted: Wed Apr 04, 2007 10:36 am 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
You need a transaction to use Hibernate,
try Required instead of Supports

_________________
Edwin van der Elst
Finalist IT Group


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 3:15 am 
Newbie

Joined: Fri Dec 29, 2006 1:17 am
Posts: 3
I have tried with "REQUIRES" and it works fine. I need to get it working with SUPPORTS.

Cheers,
Sanjay


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 3:17 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You can't have no transaction and bind the current Session to the current (non-existing) transaction. Why do you want to use SUPPORTS? It's very rare that you can say "if a method on his bean is called, it's fine if a transaction context is present, but it doesn't matter if it's not there". Especially in a bean that does data access this makes not much sense.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.