-->
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.  [ 7 posts ] 
Author Message
 Post subject: Unable to Locate current JTA Transaction
PostPosted: Sun Feb 25, 2007 9:07 pm 
Newbie

Joined: Sun Feb 25, 2007 8:20 pm
Posts: 2
Location: Sacramento, CA
I'm trying to use Jboss 4.0.4 + Hibernate 3.2 cr2 + JTA and get this error when calling sf.getCurrentSession() .. "Unable to locate current JTA Transaction". When I use sf.openSession() it works fine for some reason, but I would like to use getCurrentSession() like the docs suggest. I'm not using EJBs/CMT in my app.

Any idea what I'm doing wrong? I've read thru the jboss integration and session/transaction handling docs but can't figure it out.

MBean startup:

15:01:22,390 INFO [SettingsFactory] JDBC driver: SQLServer, version: 2.2.0022
15:01:22,390 INFO [Dialect] Using dialect: org.hibernate.dialect.SQLServerDialect
15:01:22,390 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JTATransactionFactory
15:01:22,390 INFO [NamingHelper] JNDI InitialContext properties:{}
15:01:22,390 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
15:01:22,406 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
15:01:22,406 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
15:01:22,406 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
15:01:22,406 INFO [SettingsFactory] Automatic flush during beforeCompletion(): enabled
15:01:22,406 INFO [SettingsFactory] Automatic session close at end of transaction: enabled
15:01:22,406 INFO [SettingsFactory] Scrollable result sets: enabled
15:01:22,406 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
15:01:22,406 INFO [SettingsFactory] Connection release mode: after_statement
15:01:22,406 INFO [SettingsFactory] Default batch fetch size: 1
15:01:22,406 INFO [SettingsFactory] Generate SQL with comments: disabled
15:01:22,421 INFO [SettingsFactory] Order SQL updates by primary key: disabled
15:01:22,421 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
15:01:22,421 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
15:01:22,421 INFO [SettingsFactory] Query language substitutions: {}
15:01:22,421 INFO [SettingsFactory] Second-level cache: enabled
15:01:22,421 INFO [SettingsFactory] Query cache: disabled
15:01:22,421 INFO [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
15:01:22,421 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
15:01:22,421 INFO [SettingsFactory] Structured second-level cache entries: disabled
15:01:22,421 INFO [SettingsFactory] Statistics: disabled
15:01:22,437 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
15:01:22,437 INFO [SettingsFactory] Default entity-mode: pojo
15:01:22,437 INFO [SessionFactoryImpl] building session factory
15:01:22,500 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
15:01:22,500 INFO [NamingHelper] JNDI InitialContext properties:{}
15:01:22,531 INFO [Hibernate] SessionFactory successfully built and bound into JNDI [java:/hibernate/LMDSQLServerSessionFactory]


Stack trace:



15:02:31,468 DEBUG [HibernateUtilMitigation] org.hibernate.HibernateException: Unable to locate current JTA transaction
at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:61)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:541)
at com.homeq.lossmitigation.persistence.HibernateUtilMitigation.getHibernateSession(HibernateUtilMitigation.java:63)
at com.homeq.lossmitigation.dao.UiPlanTypeDAO.getAllPlanTypes(UiPlanTypeDAO.java:65)
at com.homeq.lossmitigation.services.MitigationFacade.getAllPlanTypes(MitigationFacade.java:404)
at com.homeq.lossmitigation.struts.actions.QueueDisplayAction.execute(QueueDisplayAction.java:120)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:318)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:703)
at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:670)
at org.apache.jsp.login_jsp._jspService(login_jsp.java:43)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.homeq.ldap.filter.LoadUserFilter.doFilter(LoadUserFilter.java:103)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)




Hibernate util code:


Code:
public static Session getHibernateSession() throws ServiceLocatorException {
                    
       Session session = null;

      try
      {
         session = getSessionFactory().getCurrentSession();
      }
      catch (Exception e)
      {
            logger.debug(Utils.getStackTrace(e));
          throw new ServiceLocatorException(e);
      }

      return session;
  }



Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 26, 2007 4:38 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi smhaure.
reason being that org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:541) no current session is there

Transaction txn = null;
562 try {
563 txn = transactionManager.getTransaction();
564 if ( txn == null ) {
565 throw new HibernateException( "Unable to locate current JTA transaction" );
566 }

if you see in SessionFactoryImpl .it is clear that txn is null for your case.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 26, 2007 5:23 pm 
Newbie

Joined: Sun Feb 25, 2007 8:20 pm
Posts: 2
Location: Sacramento, CA
Dharmendra, Thanks for your reply.

I'm trying to start the tx in the constructor of my DAO but it throws the same error (actually doesn't matter where I put it , same error). I must be starting the tx incorrectly. Do I have to start the tx using a different method? here is the DAO constructor .. which throws the error.

Code:
public class UiPlanTypeDAO {
public UiPlanTypeDAO() {
    HibernateUtilMitigation.getSessionFactory().getCurrentSession().beginTransaction();


based on this example:

http://blog.hibernate.org/cgi-bin/blosxom.cgi/2005/09/

Code:
Session s = HibernateUtil.getSessionFactory().getCurrentSession();
s.beginTransaction();
   
s.save(item);
// or
HibernateUtil.getSessionFactory().getCurrentSession().save(item);
   
s.getTransaction().commit();



I see from the jboss/hibernate wiki page the tx must exist first but I don't see how that reconciles with the above example ..

Quote:
Since version 3.0.1, Hibernate itself has the ability to track the "current session" and to expose that to applications through the getCurrentSession() method of the SessionFactory.

If the given ~SessionFactory has already bound a session to the "current context", then sucessive calls to getCurrentSession() will continue to return the same session;

if not, a new Session is generated, bound to the "current context", and then returned.

One caveat to note here is that due to the use of the Transaction to
scope or track the current session, the JTA transaction must be started
prior to the session initially being bound.


THanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 27, 2007 3:05 am 
Newbie

Joined: Sun Sep 03, 2006 1:21 am
Posts: 9
hibernate 3.2.*
jboss 4.0.5.GA

im getting the same "unable to locate jta transaction" @TransactionAttributeType.SUPPORTS but not with @TransactionAttributeType.REQUIRED on ejb 3 session bean[slsb].

i use getCurrentSession().

i understand hibernate session needs a transaction but what happens when you need to mark something as read only.

as i understand the only way to mark this is by using @TransactionAttributeType.SUPPORTS.

is there a way to tell a hibernate session that it should be readonly so that the session doesnot look for a transaction? any work around this if you really need to use @TransactionAttributeType.SUPPORTS?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 27, 2007 6:36 am 
Newbie

Joined: Thu Oct 28, 2004 1:15 am
Posts: 8
Hi,

You need to attach the session with the transaction of the application server. Do you do something like this in the session-factory of hibernate.cfg.xml:

transactionManagerFactory="org.hibernate.transaction.CMTTransactionFactory"
transactionManagerLookup="org.hibernate.transaction.WeblogicTransactionManagerLookup"

Regards,
Søren


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 27, 2007 2:04 pm 
Newbie

Joined: Sun Sep 03, 2006 1:21 am
Posts: 9
thanks for your reply.

thats not what my question is about.
i already have what you suggest.

again my question is if you need to use ejb 3 @TransactionAttributeType.SUPPORTS on session bean method then how do you avoid "unable to locate current jta transaction"?


Top
 Profile  
 
 Post subject: Re: Unable to Locate current JTA Transaction
PostPosted: Tue May 25, 2010 8:22 am 
Newbie

Joined: Tue May 25, 2010 8:15 am
Posts: 1
But what can I do, if I want to use hibernate without transaction? E.g. after an unsuccesful transcation, which was rolled back, a log and auditing mechanism want to find hibernate objects.


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