Tests fail with a TransactionRequiredException: no transaction is in progress exception when loading both JPA and Neo4J configurations

烂漫一生 提交于 2019-11-28 13:55:24
Stephane

I could solve the issue with the solution provided at Implementing Spring ChainedTransactionManager according to the "best efforts 1PC" pattern with a chained transaction manager, following a tip by Simon at How do I properly set up cross-store persistence using Spring Data JPA + Neo4j?

I just had to change my Neo4j configuration. I didn't even have to touch anything in the other JPA transaction manager.

Here is my Neo4j configuration:

@EnableNeo4jRepositories(basePackages = { "it.robot.data.neo4j.repository" })
@EnableTransactionManagement
@ComponentScan(basePackages = { "it.robot.data.neo4j.service" })
public class Neo4JRepositoryConfiguration extends Neo4jConfiguration {

  private static Logger logger = LoggerFactory.getLogger(Neo4JRepositoryConfiguration.class);

  public static final String URL = "http://localhost:7474/db/data/";
  public static final String LOGIN = "neo4j";
  public static final String PASSWORD = "xxxxx";

  Neo4JRepositoryConfiguration() {
    setBasePackage("it.robot.data.neo4j.domain");
  }

  @Bean
  GraphDatabaseService graphDatabaseService() {
    return new SpringCypherRestGraphDatabase(URL, LOGIN, PASSWORD);
  }

  @Autowired
  LocalContainerEntityManagerFactoryBean entityManagerFactory;

  @Override
  public PlatformTransactionManager neo4jTransactionManager(
      GraphDatabaseService graphDatabaseService) {
    return new ChainedTransactionManager(
        new JpaTransactionManager(entityManagerFactory.getObject()),
        new JtaTransactionManagerFactoryBean(graphDatabaseService).getObject());
  }

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!