Announcement Announcement Module
Collapse
No announcement yet.
JTA + JPA/Hibernate + Glassfish Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JTA + JPA/Hibernate + Glassfish

    Hi,

    Im' trying to configure my application to use JTA transactions running on glassfish. I keep getting a TypeMismatchException every time I start the server :

    Code:
    Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.springframework.transaction.jta.JtaTransactionManager] to required type [javax.transaction.TransactionManager] for property 'transactionManager'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [org.springframework.transaction.jta.JtaTransactionManager] to required type [javax.transaction.TransactionManager] for property 'transactionManager': no matching editors or conversion strategy found
    	at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1289)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    	... 193 more
    I've been searching the net all day and can't find a decent solution to this problem. Below are my config files so far :

    META-INF/persistence.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns="/java.sun.com/xml/ns/persistence"
    	xmlns:xsi="/www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="/java.sun.com/xml/ns/persistence
    /java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    	version="1.0">
    	<persistence-unit name="xxx-persistence-unit"
    		transaction-type="JTA">
    		<jta-data-source>java:jdbc/xxxxsample</jta-data-source>
    		<properties>
    			<property name="hibernate.ejb.cfgfile" value="/hibernate/hibernate.cfg.xml" />
    		    <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
    		    <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
           </properties>
    	</persistence-unit>
    </persistence>
    ApplicationContext.xml :

    Code:
    <context:annotation-config />
    <jee:jndi-lookup id="dataSource" jndi-name="jdbc/xxxxxsample" resource-ref="true"/>
    	
    	
    	<bean id="entityManagerFactory"
    		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    				<property name="showSql" value="true" />
    				<property name="generateDdl" value="true" />
    			</bean>
    		</property>
    		<property name="persistenceUnitName" value="xxxxx-persistence-unit" />
    		<property name="jpaProperties">
    			<props>
    				<!--<prop key="hibernate.connection.driver_class"> org.hsqldb.jdbcDriver </prop>
    				<prop key="hibernate.connection.url"> jdbc:hsqldb:mem:demo </prop>
    				<prop key="hibernate.connection.username"> sa </prop>
    				<prop key="hibernate.connection.password"> </prop>-->
    				<prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop>
    				<prop key="hibernate.show_sql">true</prop>
    				<prop key="hibernate.ejb.naming_strategy">xxx.xxx.xxx.sample.integration.common.hibernate.xxxxNamingStrategy</prop>
    				<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
    				
    			</props>
    		</property>
    		<property name="loadTimeWeaver">
                <bean class="org.springframework.instrument.classloading.glassfish.GlassFishLoadTimeWeaver"/>
            </property>
    	</bean>
    	<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" />
    Can anyone tell me what's wrong ?
    Last edited by Domenique; Aug 19th, 2009, 08:23 AM.

  • #2
    You've posted in the forum for the Spring Integration project. You should post this in the Data Access forum.

    Comment


    • #3
      By the way, when using the Spring LocalContainerEntityManagerFactoryBean to create an EntityManager, you do not need to configure the transaction-type and jta-data-source in the persistence.xml configuration file.

      For example, have a look at the configuration excerpts in the docs:
      http://static.springframework.org/sp...a-setup-lcemfb

      Hope that helps.
      Mark

      Comment


      • #4
        The definitely solution for JPA + JTA Transactions!

        Dear Mark Fisher,

        thank you a lot for sharing your knowledge with community. I`ve spent many days looking for a solution, to work with plain JPA and JTA transactions with Spring (I`m using Glassfish).

        The details you gave us makes all the difference.

        Best Regards,
        Alexandre Verri

        Comment

        Working...
        X