Announcement Announcement Module
Collapse
No announcement yet.
Spring 3.1.1 + Jboss 7.1.1 + JTA, No Session found for current thread Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3.1.1 + Jboss 7.1.1 + JTA, No Session found for current thread

    Hi,

    I had been setting up JTA transaction in my app.
    I have search through the forums and the internet.
    But still, i not able to get it work.

    I have done the following.
    1. set up my data source in jboss 7. I am using MYSQL
    2. set up jndi lookup in applicationContext.xml
    3. created org.springframework.transaction.jta.JtaTransaction Manager beans
    4. using AOP tx.:advice to pointcut my 'service' layer


    Below is the log output for the jboss datasource and the JTAtransactionManager

    Code:
    [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:/ecatalogAdminDS]
    [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
    [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) JBAS010400: Bound data source [java:/ecatalogDS]
    
    [org.springframework.transaction.jta.JtaTransactionManager] (MSC service thread 1-2) Using JTA UserTransaction: org.jboss.tm.usertx.client.ServerVMClientUserTransaction@9f515e
    [org.springframework.transaction.jta.JtaTransactionManager] (MSC service thread 1-2) Using JTA TransactionManager: com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate@c2336
    [org.springframework.transaction.jta.JtaTransactionManager] (MSC service thread 1-2) Using JTA TransactionSynchronizationRegistry: com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple@dbda5c


    Below is the error stack trace.
    Code:
    org.hibernate.HibernateException: No Session found for current thread
    	org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
    	org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:941)
    	com.b2b.spring.dao.HibernateBaseDAO.getCurrentSession(HibernateBaseDAO.java:25)
    	com.b2b.admin.dao.OrganizationDAOImpl.listById(OrganizationDAOImpl.java:33)
    	com.b2b.admin.service.OrganizationServiceImpl.findById(OrganizationServiceImpl.java:28)
    	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	java.lang.reflect.Method.invoke(Method.java:601)
    	org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
    	org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    	org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
    	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	$Proxy38.findById(Unknown Source)


    My applicationContext.xml
    Code:
    <jee:jndi-lookup id="ecatalogAdminDS" jndi-name="java:/ecatalogAdminDS"></jee:jndi-lookup>
    <jee:jndi-lookup id="ecatalogDS" jndi-name="java:/ecatalogDS"></jee:jndi-lookup>
    
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
    
    <tx:jta-transaction-manager  transaction-manager="transactionManager"/>
    
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    		<tx:attributes>
    			<tx:method name="list*" read-only="true" />
    			<tx:method name="find*" read-only="true" />
    			<tx:method name="*" read-only="true" />
    		</tx:attributes>
    	</tx:advice>
    
    
    <aop:config>
    		<aop:pointcut id="adminServiceMethods"
    			expression="execution(* com.b2b.admin.service.*.*(..))" />
    		<aop:advisor advice-ref="txAdvice" pointcut-ref="adminServiceMethods" />
    	</aop:config>
    
    <bean id="ecatalogAdminSessionFactory"
    		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    
    		<property name="packagesToScan" value="com.b2b.security,com.b2b.admin"/>
    		<property name="hibernateProperties">
    			<ref bean="hibernateProperties" />
    		</property>
    		<property name="dataSource">
    			<ref local="ecatalogAdminDS" />
    		</property>
    	</bean>
    	
    	<bean id="ecatalogSessionFactory"
    		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    
    		<property name="packagesToScan" value="com.b2b.security,com.b2b.admin"/>
    		<property name="hibernateProperties">
    			<ref bean="hibernateProperties" />
    		</property>
    		<property name="dataSource">
    			<ref local="ecatalogDS" />
    		</property>
    	</bean>

    this is my hibernateProperties

    Code:
    hibernate.dialect=org.hibernate.dialect.MySQLDialect
    hibernate.show_sql=true
    #set this to avoid "cannot open connection" problem
    hibernate.connection.release_mode=after_transaction

    I hope i am giving enough informations.
    I have been trying days to make it work.

    Thank you in advance.

  • #2
    Hello

    First - check Spring JIRA issue https://jira.springsource.org/browse/SPR-9020.

    I had the same problem after switching to Hibernate 4 - suddenly all of my @Transactional(PROPAGATION_SUPPORTS/readOnly) methods failed because of non existing Hibernate Session. I don't quite know what is the default propagation for
    Code:
    <tx:method name="..." read-only="true" />
    It seems it is REQUIRED, but I can't check right now.

    For me I had to use my own extension of org.springframework.orm.hibernate4.SpringSessionCo ntext with the following method overriden:
    Code:
    	@Override
    	public Session currentSession() throws HibernateException
    	{
    		try {
    			return super.currentSession();
    		} catch (HibernateException e) {
    			try {
    				return this.sessionFactory.openSession();
    			}
    			catch (IllegalStateException ex) {
    				throw new HibernateException(ex.getMessage());
    			}
    		}
    	}
    and the following Hibernate property:
    Code:
    hibernate.current_session_context_class = org.myself.SessionCreatingSpringSessionContext
    All worked with Hibernate3, because there the class had the following method:
    Code:
    	public Session currentSession() throws HibernateException {
    		try {
    			return (org.hibernate.classic.Session) SessionFactoryUtils.doGetSession(this.sessionFactory, false);
    		}
    		catch (IllegalStateException ex) {
    			throw new HibernateException(ex.getMessage());
    		}
    	}
    which created the session using SessionFactoryUtils.

    See if this woks for you.

    regards
    Grzegorz Grzybek

    Comment


    • #3
      For starters you aren't telling hibernate you are using JTA you are missing the properties in your hibernate properties for that.

      You need to set the hibernate.transaction.jta.platform to (judging from the fact you use jboss) org.hibernate.service.jta.platform.internal.JBossS tandAloneJtaPlatform. While using JPA we also had to (additionally set the hibernate.current_session_context_class property to jta).

      Next

      I don't quite know what is the default propagation for
      The default propagation is always REQUIRED, regardless of the readOnly fact or not.

      Another note you don't need both a JtaTransactionManager and the tx:jta-transaction-manager. I suggest use only the latter, that also detects which server you are on and register the appropriate JtaTransactionManager.
      Last edited by Marten Deinum; Dec 5th, 2012, 02:15 AM.

      Comment


      • #4
        hi, guys

        Thanks for your feedback.
        I had tried based on Marteen replied.

        i upgraded my spring libraries to 3.1.3
        I am using hibernate 4.1.7

        I did some searching, and i found this hyperlink
        https://hibernate.onjira.com/browse/HHH-3676

        However,
        i am using this property
        hibernate.current_session_context_class=jta
        rather than extending to a custom class.

        I get this errors
        Code:
        10:25:13,562 FATAL [com.arjuna.ats.jts] (http-localhost-127.0.0.1-8080-1) ARJUNA022006: The ORB has not been initialized yet
        10:25:13,562 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/eCatalog].[eCatalog]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet eCatalog threw exception: org.hibernate.HibernateException: Problem locating/validating JTA transaction
        	at org.hibernate.context.internal.JTASessionContext.currentSession(JTASessionContext.java:101) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
        	at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:941) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
        	at com.b2b.spring.dao.HibernateBaseDAO.getCurrentSession(HibernateBaseDAO.java:25) [classes:]
        	at com.b2b.admin.dao.OrganizationDAOImpl.listById(OrganizationDAOImpl.java:33) [classes:]
        	at com.b2b.admin.service.OrganizationServiceImpl.findById(OrganizationServiceImpl.java:28) [classes:]
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_09]
        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_09]
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_09]
        	at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_09]


        Here are my latest hibernate.properties

        Code:
        hibernate.dialect=org.hibernate.dialect.MySQLDialect
        hibernate.show_sql=true
        #set this to avoid "cannot open connection" problem
        hibernate.connection.release_mode=after_transaction
        #hibernate.transaction.jta.platform=org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform
        hibernate.transaction.jta.platform=org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform
        
        hibernate.current_session_context_class=jta
        hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup
        hibernate.transaction.factory_class=org.hibernate.transaction.JTATransactionFactory
        Last edited by onesolution; Dec 5th, 2012, 09:42 PM. Reason: apply code formatting

        Comment


        • #5
          You should use either JtaPlatform OR session_context_class but not both (The JtaPlatform is basically the replacement for the older integration stuff). Which JtaPlatform to use depends on your server but judging from your configuration that is already the case.

          Comment


          • #6
            Participating transaction failed - marking existing transaction as rollback-only

            Hi,

            I tried using below hibernate.property
            Code:
            hibernate.dialect=org.hibernate.dialect.MySQLDialect
            hibernate.show_sql=true
            #set this to avoid "cannot open connection" problem
            hibernate.connection.release_mode=after_transaction
            #hibernate.transaction.jta.platform=org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform
            hibernate.transaction.jta.platform=org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform
            
            #hibernate.current_session_context_class=jta
            hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup
            hibernate.transaction.factory_class=org.hibernate.transaction.JTATransactionFactory

            I able to resolve this
            ARJUNA022006: The ORB has not been initialized yet
            by removing jbossjts-4.16.4.Final.jar

            I am getting this error now.
            Code:
            09:58:47,515 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (http-localhost-127.0.0.1-8080-1) Creating new transaction with name [com.b2b.security.service.AuthenticationServiceImpl.supports]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
            09:58:47,531 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (http-localhost-127.0.0.1-8080-1) Initiating transaction commit
            09:58:47,531 DEBUG [org.springframework.security.authentication.ProviderManager] (http-localhost-127.0.0.1-8080-1) Authentication attempt using $Proxy43
            09:58:47,531 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (http-localhost-127.0.0.1-8080-1) Creating new transaction with name [com.b2b.security.service.AuthenticationServiceImpl.authenticate]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
            09:58:47,531 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (http-localhost-127.0.0.1-8080-1) Participating in existing transaction
            09:58:47,562 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (http-localhost-127.0.0.1-8080-1) Participating transaction failed - marking existing transaction as rollback-only
            09:58:47,562 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (http-localhost-127.0.0.1-8080-1) Setting JTA transaction rollback-only
            09:58:47,562 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (http-localhost-127.0.0.1-8080-1) Initiating transaction rollback
            09:58:47,562 DEBUG [org.springframework.security.web.context.HttpSessionSecurityContextRepository] (http-localhost-127.0.0.1-8080-1) SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
            09:58:47,562 DEBUG [org.springframework.security.web.context.SecurityContextPersistenceFilter] (http-localhost-127.0.0.1-8080-1) SecurityContextHolder now cleared, as request processing completed
            09:58:47,562 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/eCatalog].[eCatalog]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet eCatalog threw exception: org.hibernate.HibernateException: Unable to locate current JTA transaction
            	at org.hibernate.context.internal.JTASessionContext.currentSession(JTASessionContext.java:88) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
            	at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:90) [org.springframework.orm-3.1.3.RELEASE.jar:3.1.3.RELEASE]
            	at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:941) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
            	at com.b2b.spring.dao.HibernateBaseDAO.getCurrentSession(HibernateBaseDAO.java:25) [classes:]
            	at com.b2b.admin.dao.OrganizationDAOImpl.listById(OrganizationDAOImpl.java:33) [classes:]
            	at com.b2b.admin.service.OrganizationServiceImpl.findById(OrganizationServiceImpl.java:28) [classes:]

            And this is my pointcut

            Code:
            <tx:advice id="txAdvice" transaction-manager="transactionManager">
            		<tx:attributes>
            			<tx:method name="update*" propagation="REQUIRES_NEW" />
            			<tx:method name="create*" propagation="REQUIRES_NEW" />
            			<tx:method name="save*" propagation="REQUIRES_NEW" />
            			<tx:method name="delete*" propagation="REQUIRED" />
            			<tx:method name="upload*" propagation="REQUIRED" />
            			<tx:method name="list*" read-only="true" />
            			<tx:method name="find*" read-only="true" />
            			<tx:method name="*" read-only="true" />
            		</tx:attributes>
            	</tx:advice>

            Thank you
            Last edited by onesolution; Dec 7th, 2012, 01:21 AM.

            Comment


            • #7
              Hi,

              Anyone had any idea ?

              Comment

              Working...
              X