Results 1 to 9 of 9

Thread: Local EJB, Hibernate and JTA?

  1. #1
    Join Date
    Jan 2006
    Location
    Oslo, Norway
    Posts
    13

    Default Local EJB, Hibernate and JTA?

    Hi

    I have the following configuration of my Hibernate sessionfactory and the JTA transactionmanager on Websphere.

    !--Transaction manager-->
    <bean id="rep.pen.jtaTransactionManager" class="org.springframework.transaction.jta.WebSphe reTransactionManagerFactoryBean"/>

    <!-- Hibernate SessionFactory Definition -->
    <bean id="rep.pen.sessionFactory"
    class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
    <property name="dataSource">
    <ref bean="rep.pen.dataSource" />
    </property>
    <property name="jtaTransactionManager" ref="rep.pen.jtaTransactionManager"/>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.DB2400Dialect
    </prop>
    <prop key="hibernate.query.jpaql_strict_compliance">
    true
    </prop>
    <prop key="hibernate.show_sql">false</prop>
    <prop key="hibernate.connection.pool_size">50</prop>
    <!--
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
    -->
    </props>
    </property>
    <property name="entityInterceptor">
    <ref bean="persistentDomainObjectHibernateInterceptor" />
    </property>
    <property name="eventListeners">
    <map>
    <!-- This event listener should be removed as soone as lazy loading is handled properly -->
    <!-- <entry key="post-load"><bean class="no.nav.repository.pensjon.util.EagerLazyLoa ding"/></entry>-->

    </map>
    </property>
    <property name="annotatedClasses" ref="rep.pen.annotatedDomainClasses"/>
    </bean>

    I want to use local SLSB to wrap a POJO that dows my logic (using hibernate). The session is opened using OpenSessionInView.

    When doing this I get the following exception in my log:

    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'rep.pen.hibernateTemplate' defined in class path resource [modules/rep-pen-context.xml]: Cannot resolve reference to bean 'rep.pen.sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'rep.pen.sessionFactory' defined in class path resource [modules/rep-pen-context.xml]: Cannot resolve reference to bean 'rep.pen.jtaTransactionManager' while setting bean property 'jtaTransactionManager'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'rep.pen.jtaTransactionManager' defined in class path resource [modules/rep-pen-context.xml]: Cannot create inner bean 'org.springframework.transaction.jta.WebSphereTran sactionManagerFactoryBean#6cb66cb6' of type [org.springframework.transaction.jta.WebSphereTrans actionManagerFactoryBean] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.transaction.jta.WebSphereTran sactionManagerFactoryBean#6cb66cb6' defined in class path resource [modules/rep-pen-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.transaction.jta.WebSphereTrans actionManagerFactoryBean]: Constructor threw exception; nested exception is org.springframework.transaction.TransactionSystemE xception: Could not access WebSphere's TransactionManagerFactory.getTransactionManager method; nested exception is java.lang.ClassCastException: com.ibm.ws.Transaction.JTA.TranManagerSet incompatible with javax.transaction.TransactionManager

    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'rep.pen.sessionFactory' defined in class path resource [modules/rep-pen-context.xml]: Cannot resolve reference to bean 'rep.pen.jtaTransactionManager' while setting bean property 'jtaTransactionManager'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'rep.pen.jtaTransactionManager' defined in class path resource [modules/rep-pen-context.xml]: Cannot create inner bean 'org.springframework.transaction.jta.WebSphereTran sactionManagerFactoryBean#6cb66cb6' of type [org.springframework.transaction.jta.WebSphereTrans actionManagerFactoryBean] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.transaction.jta.WebSphereTran sactionManagerFactoryBean#6cb66cb6' defined in class path resource [modules/rep-pen-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.transaction.jta.WebSphereTrans actionManagerFactoryBean]: Constructor threw exception; nested exception is org.springframework.transaction.TransactionSystemE xception: Could not access WebSphere's TransactionManagerFactory.getTransactionManager method; nested exception is java.lang.ClassCastException: com.ibm.ws.Transaction.JTA.TranManagerSet incompatible with javax.transaction.TransactionManager

    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'rep.pen.jtaTransactionManager' defined in class path resource [modules/rep-pen-context.xml]: Cannot create inner bean 'org.springframework.transaction.jta.WebSphereTran sactionManagerFactoryBean#6cb66cb6' of type [org.springframework.transaction.jta.WebSphereTrans actionManagerFactoryBean] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.transaction.jta.WebSphereTran sactionManagerFactoryBean#6cb66cb6' defined in class path resource [modules/rep-pen-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.transaction.jta.WebSphereTrans actionManagerFactoryBean]: Constructor threw exception; nested exception is org.springframework.transaction.TransactionSystemE xception: Could not access WebSphere's TransactionManagerFactory.getTransactionManager method; nested exception is java.lang.ClassCastException: com.ibm.ws.Transaction.JTA.TranManagerSet incompatible with javax.transaction.TransactionManager

    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.transaction.jta.WebSphereTran sactionManagerFactoryBean#6cb66cb6' defined in class path resource [modules/rep-pen-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.transaction.jta.WebSphereTrans actionManagerFactoryBean]: Constructor threw exception; nested exception is org.springframework.transaction.TransactionSystemE xception: Could not access WebSphere's TransactionManagerFactory.getTransactionManager method; nested exception is java.lang.ClassCastException: com.ibm.ws.Transaction.JTA.TranManagerSet incompatible with javax.transaction.TransactionManager

    Caused by: org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.transaction.jta.WebSphereTrans actionManagerFactoryBean]: Constructor threw exception; nested exception is org.springframework.transaction.TransactionSystemE xception: Could not access WebSphere's TransactionManagerFactory.getTransactionManager method; nested exception is java.lang.ClassCastException: com.ibm.ws.Transaction.JTA.TranManagerSet incompatible with javax.transaction.TransactionManager

    Caused by: org.springframework.transaction.TransactionSystemE xception: Could not access WebSphere's TransactionManagerFactory.getTransactionManager method; nested exception is java.lang.ClassCastException: com.ibm.ws.Transaction.JTA.TranManagerSet incompatible with javax.transaction.TransactionManager

    Caused by: java.lang.ClassCastException: com.ibm.ws.Transaction.JTA.TranManagerSet incompatible with javax.transaction.TransactionManager

    at org.springframework.transaction.jta.WebSphereTrans actionManagerFactoryBean.<init>(WebSphereTransacti onManagerFactoryBean.java:110)

    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)

    Any ideas? Anye help would be appreciated.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Please use [ code][/code ] tags (without the spaces) when posting code, that way your code remains readable.

    Which version of Websphere are you on?
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jan 2006
    Location
    Oslo, Norway
    Posts
    13

    Default

    Hi

    Thanks for your tip ;-)

    I am using Websphere 6.1 and Spring 2.0.1. I have changed to using the JtaTransactionManager and not the Websphere specific one. Now getting this error

    Code:
    Caused by: java.lang.IllegalStateException: Either 'userTransaction' or 'userTransactionName' or 'transactionManager' or 'transactionManagerName' must be specified
    when I change to using ...jta.JtaTransactionManager.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    If you use websphere 6.0 or higher it is recommended to use the WebSphereUowTransactionManager.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Jan 2006
    Location
    Oslo, Norway
    Posts
    13

    Default

    Ok, but what if I cannot upgrade spring for a while and need to test my transactions.

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    I assumed you where on Spring 2.5, which obviously isn't the case.

    The WebSphereTransactionManagerFactoryBean you used should work. You might try the configuration where the use the combination of the JtaTransactionManager and the WebSphere FactoryBean as explained in the javadoc.

    Next to that you might have a classloading issue, make sure that there is only 1 version of the jta.jar (or the classes in there) on your classpath.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Jan 2006
    Location
    Oslo, Norway
    Posts
    13

    Default

    I now have this config and error message

    Code:
    bean id="wsJtaTm" class="org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean"/>
    
    
    <bean id="rep.pen.jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    
    <property name="transactionManager" ref="wsJtaTm"/>
    
    </bean>
    
     
    
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rep.pen.hibernateTemplate' defined in class path resource [modules/rep-pen-context.xml]: Cannot resolve reference to bean 'rep.pen.sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rep.pen.sessionFactory' defined in class path resource [modules/rep-pen-context.xml]: Cannot resolve reference to bean 'rep.pen.jtaTransactionManager' while setting bean property 'jtaTransactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rep.pen.jtaTransactionManager' defined in class path resource [modules/rep-pen-context.xml]: Cannot resolve reference to bean 'wsJtaTm' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'wsJtaTm' defined in class path resource [modules/rep-pen-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean]: Constructor threw exception; nested exception is org.springframework.transaction.TransactionSystemException: Could not access WebSphere's TransactionManagerFactory.getTransactionManager method; nested exception is java.lang.ClassCastException: com.ibm.ws.Transaction.JTA.TranManagerSet incompatible with javax.transaction.TransactionManager
    
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rep.pen.sessionFactory' defined in class path resource [modules/rep-pen-context.xml]: Cannot resolve reference to bean 'rep.pen.jtaTransactionManager' while setting bean property 'jtaTransactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rep.pen.jtaTransactionManager' defined in class path resource [modules/rep-pen-context.xml]: Cannot resolve reference to bean 'wsJtaTm' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'wsJtaTm' defined in class path resource [modules/rep-pen-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean]: Constructor threw exception; nested exception is org.springframework.transaction.TransactionSystemException: Could not access WebSphere's TransactionManagerFactory.getTransactionManager method; nested exception is java.lang.ClassCastException: com.ibm.ws.Transaction.JTA.TranManagerSet incompatible with javax.transaction.TransactionManager
    
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rep.pen.jtaTransactionManager' defined in class path resource [modules/rep-pen-context.xml]: Cannot resolve reference to bean 'wsJtaTm' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'wsJtaTm' defined in class path resource [modules/rep-pen-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean]: Constructor threw exception; nested exception is org.springframework.transaction.TransactionSystemException: Could not access WebSphere's TransactionManagerFactory.getTransactionManager method; nested exception is java.lang.ClassCastException: com.ibm.ws.Transaction.JTA.TranManagerSet incompatible with javax.transaction.TransactionManager
    
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'wsJtaTm' defined in class path resource [modules/rep-pen-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean]: Constructor threw exception; nested exception is org.springframework.transaction.TransactionSystemException: Could not access WebSphere's TransactionManagerFactory.getTransactionManager method; nested exception is java.lang.ClassCastException: com.ibm.ws.Transaction.JTA.TranManagerSet incompatible with javax.transaction.TransactionManager
    
    Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean]: Constructor threw exception; nested exception is org.springframework.transaction.TransactionSystemException: Could not access WebSphere's TransactionManagerFactory.getTransactionManager method; nested exception is java.lang.ClassCastException: com.ibm.ws.Transaction.JTA.TranManagerSet incompatible with javax.transaction.TransactionManager
    
    Caused by: org.springframework.transaction.TransactionSystemException: Could not access WebSphere's TransactionManagerFactory.getTransactionManager method; nested exception is java.lang.ClassCastException: com.ibm.ws.Transaction.JTA.TranManagerSet incompatible with javax.transaction.TransactionManager
    
    Caused by: java.lang.ClassCastException: com.ibm.ws.Transaction.JTA.TranManagerSet incompatible with javax.transaction.TransactionManager
    
    at org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean.<init>(WebSphereTransactionManagerFactoryBean.java:110)
    This can typically be a classloading issue?

  8. #8
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    I expect it to be a classloading issue, a small search points to this thread which removed the jta.jar from the library (jta.jar is also/already provided by WebSphere and shouldn't be included in your app). Also playing around with the classloading order (PARENT_FIRST or LAST might help).

    However I expect it to be a classloading issue especially the 'incompatible with' message points in that direction.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  9. #9
    Join Date
    Jan 2006
    Location
    Oslo, Norway
    Posts
    13

    Default

    It was classloading issues. jta.jar was in two different versions (one in tha application) and one in the server. Removed it from tha application, and it seems to be working now...

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •