Question

I am trying to use JtaTransactionManager in spring/hibernate. I have below configuration.

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">  
    <property name="userTransactionName" value="java:comp/UserTransaction"></property>  
</bean> 

Now can i mark my service methods with @Transactional ? or do i need any extra configuration to use @Transactional ? do i need to add ?

Était-ce utile?

La solution

An annotation is nothing more then metadata, so only slapping an annotation on there and expect it to magically work isn't going to happen.

To make @Transactional work you need to tell spring that you want to use annotation to drive your transactions. For this add the <tx:annotation-driven /> tag to your configuration.

However that probably isn't going to be all there is needed as you also need to configure hibernate appropriately for JTA.

A small tip instead of defining the bean, use the shorter <tx:jta-transaction-manager />. This will do some detection on which app server you are running and configure the appropriate transaction manager for you. See http://docs.spring.io/spring/docs/current/spring-framework-reference/html/transaction.html#transaction-application-server-integration for more information.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top