Announcement Announcement Module
Collapse
No announcement yet.
Glassfish v3.0.1 / JTA / (JPA2/Hibernate3.5) / Spring 3 exception mapping. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Glassfish v3.0.1 / JTA / (JPA2/Hibernate3.5) / Spring 3 exception mapping.

    EXCEPTION TRANSLATION NOT WORKING FOR PERSISTENCE WITH GLASSFISH JTA.

    Could someone help, please? Spring-certified Professional here CLUELESS - getting org.springframework.transaction.UnexpectedRollback Exception instead of org.springframework.dao.DataIntegrityViolationExce ption because I cannot find how to configure Glassfish JTA to work with Spring exception translation capabilities. Here's my new config:

    jta-glassfish.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:amq="http://activemq.apache.org/schema/core" xmlns:jms="http://www.springframework.org/schema/jms"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:jee="http://www.springframework.org/schema/jee"
    	xsi:schemaLocation="
    	http://www.springframework.org/schema/context
    	http://www.springframework.org/schema/context/spring-context-3.0.xsd
    	http://www.springframework.org/schema/beans 
    	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    	http://www.springframework.org/schema/tx 
    	http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
    	http://www.springframework.org/schema/aop 
    	http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
    	http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.3.2.xsd  
    	http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd 
    	http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
    
    	<!-- database connection pools -->
    
    	<!-- <jee:jndi-lookup id="dataSource" jndi-name="jdbc/postgresXA" /> -->
    
    	<bean
    		class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
    		<property name="persistenceUnits">
    			<map>
    				<entry key="tasktide" value="persistence/tasktide" />
    
    			</map>
    		</property>
    		<property name="defaultPersistenceUnitName" value="tasktide" />
    	</bean>
    	
    	
    
    	<!-- <jee:jndi-lookup id="entityManagerFactory" jndi-name="persistence/tasktide" 
    		/> -->
    
    		<bean id="entityManagerFactory"
    			class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    			<property name="persistenceUnitName" value="tasktide" />
    			<property name="jpaVendorAdapter">
    				<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    					<property name="showSql" value="true" />
    					<property name="database" value="POSTGRESQL" />
    				</bean>
    			</property>
    
    			<property name="jpaProperties">
    				<props>
    					<prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.SunONETransactionManagerLookup
    					</prop>
    				
    				</props>
    			</property>
    		
    		</bean>
    
    
    		<!-- jms connections -->
    
    		<jee:jndi-lookup id="jmsConnectionFactory" jndi-name="jms/activemq" />
    
    		<jee:jndi-lookup id="emailNowQueue" jndi-name="jms/emailnow" />
    		<jee:jndi-lookup id="emailRegQueue" jndi-name="jms/emailreg" />
    		<jee:jndi-lookup id="matchNowQueue" jndi-name="jms/matchnow" />
    		<jee:jndi-lookup id="matchRegQueue" jndi-name="jms/matchreg" />
    		<jee:jndi-lookup id="statQueue" jndi-name="jms/stat" />
    
    		<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    			<property name="connectionFactory">
    				<ref bean="jmsConnectionFactory" />
    			</property>
    			<property name="defaultDestination">
    				<ref bean="emailRegQueue" />
    			</property>
    			<property name="receiveTimeout" value="1000" />
    			<property name="sessionTransacted" value="true" />
    		</bean>
    
    		<!-- transaction manager -->
    
    		<tx:annotation-driven />
    
    		<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
    
    		<!-- <tx:jta-transaction-manager /> -->
    
    	<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
    
    <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"
    		autowire-candidate="false" />
    	
    	</beans>
    
    </beans>
    persistence.xml:

    Code:
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    	version="1.0">
    
    	<persistence-unit name="tasktide" transaction-type="JTA"> <!-- JTA, RESOURCE_LOCAL -->
    
    		 <jta-data-source>jdbc/postgresXA</jta-data-source> 
    
    		<provider>org.hibernate.ejb.HibernatePersistence</provider>
    
    
    
    		<properties>
    
    
    			<!-- enable this if org.hibernate.dialect.PostgreSQLDialect does not work 
    				<property name="hibernate.dialect" value="net.sf.hibernate.dialect.PostgreSQLDialect" 
    				/> -->
    
    			<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
    
    			<!-- enable this for atomikos jta <property name="hibernate.transaction.manager_lookup_class" 
    				value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup" /> -->
    
    			<!-- 
    			<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup" 
    				/>
    				 -->
    				 
    				 
    			<!-- <property name="hibernate.transaction.factory_class" value="com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory"/> -->
    
    			<property name="hibernate.cache.provider_class"
    				value="org.hibernate.cache.SingletonEhCacheProvider" />
    
    			<property name="hibernate.cache.provider_configuration"
    				value="../ehcache.xml" />
    
    			<property name="hibernate.cache.provider_configuration_file_resource_path"
    				value="../ehcache.xml" />
    
    			<property name="hibernate.cache.use_second_level_cache"
    				value="true" />
    
    			<property name="hibernate.cache.use_query_cache" value="true" />
    
    
    
    		</properties>
    	</persistence-unit>
    </persistence>
    It works fine, but produces UnexpectedRollbackException with a wrapped javax.transaction.RollbackException, instead of providing me with an unchecked org.springsource.dao.* exception translation.

    Can it even be done?

    P.S. I placed all the jars (including jpa, jms, etc.) into the glassfishv3/domains/domain1/lib directory.

    P.P.S. Glassfish definitely sees the exceptions:

    WARNING: JTS5033: Exception [javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationExcepti on: Could not execute JDBC batch update] on [before_completion] synchronization operation.

    But it never gets seen by my code, instead I get the javax.transaction.RollbackException.

    Could someone please advise me what I am doing wrong?
    Last edited by AntonGolovin; Jan 12th, 2011, 05:28 PM.

  • #2
    Anyone on thi forum got a clue? Marten?

    Comment


    • #3
      Similar problem

      Hey - did you ever find a solution to this? I'm facing a similar problem with Glassfish/JTA.

      Exception translation works in my test environment - the correct Spring unchecked exceptions are thrown, wrapping the underlying Hibernate exception. However, when I run the application on Glassfish, the Hibernate exception is thrown, not the translated Spring exception.

      Comment


      • #4
        This is a GF problem. The cause of the exception is not set correctly. On GF 3.1 this seems to be fixed.

        Call entityManager.flush() after entityManager.merge()/remove()/persist() and the cause of the exception should be available.

        Comment

        Working...
        X