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

前端 未结 1 812
忘了有多久
忘了有多久 2020-12-11 22:20

I have a JPA web application with some integration tests against the JPA repositories. There are no integration tests against the Neo4J repositories yet.

Now, I have

相关标签:
1条回答
  • 2020-12-11 22:45

    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());
      }
    
    }
    
    0 讨论(0)
提交回复
热议问题