Results 1 to 5 of 5

Thread: Exception Translation problems with JTA

  1. #1
    Join Date
    Oct 2012
    Posts
    4

    Default Exception Translation problems with JTA

    Hi all,
    I have some problems with Exception Translation when using JtaTransactionManager

    this is my spring configuration:

    Code:
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
    
    <tx:annotation-driven transaction-manager="transactionManager"/>
    	
    	
    	<context:annotation-config/>
    	
    	<jee:jndi-lookup id="dataSource1" jndi-name="java:comp/env/jdbc/mysql" resource-ref="true"/>
    	
    	<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource1" />
    		<property name="mappingLocations">
    		
    				<value>classpath*:hbm/*.hbm.xml</value>
    			
    		</property>
    		<property name="hibernateProperties">
    			<value>
    				
    				hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
    				hibernate.show_sql=true
    				
    				
    				hibernate.transaction.factory_class=org.hibernate.engine.transaction.internal.jta.JtaTransactionFactory
    				hibernate.transaction.jta.platform=org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform
    				hibernate.connection.autocommit=true
    				hibernate.connection.release_mode=auto
    				
    				
    			</value>
    		</property>
    		
    	</bean>
    	
    	<bean id="menuService" class="it.marco.service.impl.MenuServiceImpl" />
    
    	
    	<bean id="areaDao" class="it.marco.dao.AreaDaoImpl" />
    
    	
    	
    	
    	<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
    This is my service class

    Code:
    @Transactional
    public class MenuServiceImpl implements MenuService{
    
    	
    	@Autowired
    	private AreaDao areaDao;
    
    
    	@Override
    	public void saveOrUpdateArea(DTO<Area> dto) throws DataAccessException {
    		try{
    			this.areaDao.saveOrUpdate(dto);
    			int i=0;
    		}catch(Throwable daex){
    			daex.printStackTrace();
    		}
    		
    	}
    }

    and this is my dao

    Code:
    @Repository
    public class AreaDaoImpl implements AreaDao {
    	
    	@Autowired
        protected SessionFactory sessionFactory;
    
    	
    	@Override
        public void saveOrUpdate(DTO<T> dto) throws DataAccessException {
                log.debug("DAO saveOrUpdate(DTO<T> dto)");
                log.debug("Saving/Update instance of " + this.persistentClass);
               	this.sessionFactory.getCurrentSession().saveOrUpdate(dto.getBusinessObject());
         
                log.debug("SaveOrUpdate succesfull");
        }
    	
    
    }
    On the controller that calls the service method I receive a

    org.springframework.transaction.UnexpectedRollback Exception: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is javax.transaction.RollbackException: ARJUNA016053: Could not commit transaction.

    Application Server is JBOSS 7.1.0

    I've got the same problems when using EJB3 (in this case I receive a RemoteException)

    If I use HibernateTransactionManager as txManager the controller receives a DataAccessException

    Can someone help me?

    Thanks a lot,
    Marco

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

    Default

    Don't catch and swallow exceptions like you do in your service method let them bubble up so that it can be converted.

    Another note your hibernate.connection properties/settings are useless as you are injecting a dao, next you should also only set the jtaPlatform not the factory class.
    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
    Oct 2012
    Posts
    4

    Default

    Quote Originally Posted by Marten Deinum View Post
    Don't catch and swallow exceptions like you do in your service method let them bubble up so that it can be converted.

    Another note your hibernate.connection properties/settings are useless as you are injecting a dao, next you should also only set the jtaPlatform not the factory class.
    Same problem removing try-catch in service method.

    Removing hibernate.transaction.factory_class from hibernate properties I receive no exception (and no update is done into DB). I think it is necessary for hibernate 4. I f I use EJB3 i have to set it to org.hibernate.engine.transaction.internal.jta.CMTT ransactionFactory

  4. #4
    Join Date
    Oct 2012
    Posts
    4

    Default

    Another detail: in the server.log i notice a org.hibernate.HibernateException: proxy handle is no longer valid exception.
    Can it be the cause?

    Here is the StackTrace:

    Code:
    12:21:49,453 ERROR [org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl] (http-localhost-127.0.0.1-8080-2) HHH000346: Error during managed flush [Data truncation: Data too long for column 'id' at row 1]
    12:21:49,453 WARN  [com.arjuna.ats.arjuna] (http-localhost-127.0.0.1-8080-2) ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffff0aef61a8:4307d911:507fb58d:197, org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization@10fdca9 >: org.hibernate.exception.DataException: Data truncation: Data too long for column 'id' at row 1
    	at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:71) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at $Proxy209.executeUpdate(Unknown Source)	at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:56) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2962) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3403) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	a
    [...]
    
    12:21:49,812 INFO  [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http-localhost-127.0.0.1-8080-2) HHH000106: Forcing container resource cleanup on transaction completion
    12:21:49,812 INFO  [org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl] (http-localhost-127.0.0.1-8080-2) HHH000010: On release of batch it still contained JDBC statements
    12:21:49,812 WARN  [com.arjuna.ats.jta] (http-localhost-127.0.0.1-8080-2) ARJUNA016029: SynchronizationImple.afterCompletion - failed for org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization@10fdca9 with exception: org.hibernate.HibernateException: proxy handle is no longer valid
    	at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.errorIfInvalid(AbstractProxyHandler.java:63) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:100) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at $Proxy209.clearBatch(Unknown Source)	at org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl.releaseStatements(AbstractBatchImpl.java:163) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl.release(AbstractBatchImpl.java:197) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.close(JdbcCoordinatorImpl.java:139) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.close(TransactionCoordinatorImpl.java:276) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.internal.SessionImpl.close(SessionImpl.java:349) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.internal.SessionImpl.managedClose(SessionImpl.java:540) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.afterCompletion(SynchronizationCallbackCoordinatorImpl.java:132) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.afterCompletion(RegisteredSynchronization.java:61) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]
    	at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.afterCompletion(SynchronizationImple.java:96)
    	at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.afterCompletion(TwoPhaseCoordinator.java:402)
    	at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:103)
    	at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:164)
    	at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1165)
    	at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:117)
    	at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
    	at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:167)
    	at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1010) [spring-tx-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) [spring-tx-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    	
    [...]

  5. #5
    Join Date
    Oct 2012
    Posts
    4

    Default

    It seems that using
    Code:
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
    exception translation does not occurs

    Also when using EJB3 as service layer, the exception is not translated and there's no way to catch the exception inside the service layer, since all the updates occurs when sessionFactory is closed by the EJB Container

    Does anoyone have an idea? Can you help me?

    Thanks in advance

Posting Permissions

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