I found this to be quite problematic also. It took me some time to figure out what was going wrong.
In the end I settled on this solution for the ChainedTransactionManager
Code:
<bean id="jpaTransactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="localContainerEntityManagerFactoryBean"/>
</bean>
<bean id="xaTransactionManager"
class="org.springframework.data.neo4j.transaction.ChainedTransactionManager">
<constructor-arg>
<list>
<ref bean="jpaTransactionManager"/>
<ref bean="transactionManager"/>
<!-- There is an alias so neo4jTransactionManager and
transactionManager refer to the same bean in neo4j:config
<ref bean="transactionManager"/>-->
</list>
</constructor-arg>
</bean>
<tx:annotation-driven transaction-manager="xaTransactionManager" />
Then I used this (and a few others depending on the calling thread) custom annotation.
Code:
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Transactional(propagation=Propagation.REQUIRED, readOnly=false, value="xaTransactionManager")
public @interface TxInit {
}
Mark