SpringNeo4J-impermanentGraphDatabase是否与事务注释兼容?

SpringNeo4J-impermanentGraphDatabase是否与事务注释兼容?,第1张

概述首先,我明确指出我将Spring Data用于Neo4J 2.2.0-release和Scala 2.10.我正在构建一些测试以测试我的应用程序服务.这是我按呼叫顺序排列的不同文件(我精确地说是一个概念样本,但已经过测试):MeetingServices.scala@Service class MeetingServices { @Transacti

首先,我明确指出我将Spring Data用于Neo4J 2.2.0-release和Scala 2.10.

我正在构建一些测试以测试我的应用程序服务.

这是我按呼叫顺序排列的不同文件(我精确地说是一个概念样本,但已经过测试):

MeetingServices.scala

@Serviceclass MeetingServices {  @Transactional    def save(meeting: Meeting,creator: User): ValIDationNel[MeetingFailure,Meeting] = {      try {        meetingRepository.save(meeting,creator).successNel[MeetingFailure]      } catch {        case e: Throwable => MeetingFailure("Fail to create the Meeting " + meeting + "for the user :" + creator,Some(e)).failNel[Meeting]      }    }}

在MeetingRepository.scala中保存方法:

def save(meeting: Meeting,creator: User): Meeting = { //no need to declare a transaction since this method call is wrapped insIDe the prevIoUs save() method of MeetingServices     creator.participateIn(meeting)                                               meeting.creator = creator    meetingRepository.save(meeting)}

User.class的有趣摘录:

@RelatedTo(`type` = "PARTICIPATES_IN")  val meetings: java.util.Set[Meeting] = new java.util.HashSet[Meeting]()def participateIn(meeting: Meeting) = {    meeting.creator = this   // since bIDirectional relation    meetings.add(meeting)    //#needs_transaction }

那么问题是什么?

在生产中,一切正常.发生了交易,我的会议得以保留并与其创建者链接(用户neo4j-relationship).
但是在我的环境测试中,我得到了:notinTransactionException.
为什么呢因为在用#needs_transaction注释的行上(在上面的摘录中),Relationship注释期望发生事务,并且听起来在测试期间未创建任何事务.

我将两种不同的application-context.xml用于Spring配置,一种用于我的测试,另一种用于生产中的应用程序.
用于测试的一项如下:

<?xml version="1.0" enCoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:context="http://www.springframework.org/schema/context"       xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"       xmlns:tx="http://www.springframework.org/schema/tx"       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/neo4j       http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">    <neo4j:config graphDatabaseService="graphDatabaseService"/>    <bean ID="graphDatabaseService"  />    <neo4j:repositorIEs base-package="repositorIEs"/>    <context:spring-configured/>    <context:annotation-config/>    <context:component-scan base-package="controllers,services,models,repositorIEs"/>    <tx:annotation-driven mode="aspectj"/></beans>

我在生产中使用的那个:

<?xml version="1.0" enCoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:context="http://www.springframework.org/schema/context"       xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"       xmlns:tx="http://www.springframework.org/schema/tx"       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/neo4j       http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">    <neo4j:config graphDatabaseService="graphDatabaseService"/>    <bean ID="graphDatabaseService" >        <constructor-arg index="0" value="http://myUrl/db/data/"/>        <constructor-arg index="1" value="111111"/>        <constructor-arg index="2" value="111111"/>    </bean>    <neo4j:repositorIEs base-package="repositorIEs" />    <context:spring-configured/>    <context:annotation-config/>    <context:component-scan base-package="controllers,applicationservices,repositorIEs"/>    <tx:annotation-driven mode="aspectj"/></beans>

实际上,ImpermanentGraphDatabase似乎与Spring声明的任何事务都不相关.
我怎么能这么确定?因为我最初将生产环境中的应用程序-context.xml切换为测试(使用Neo4j REST调用),而没有触及测试代码中的任何内容,所以一切正常.

我错过了什么?

提前致谢 :)

– – – – – – – -编辑 – – – – – –

实际上,它仅适用于Noe4j Rest调用.对于嵌入式数据库或ImpermanentDatabase,会发生错误.

最佳答案REST API中没有事务,每个http请求都有自己的事务. java-rest-binding使用?Null-Transaction(Manager)`.

如何实例化/注入您的服务?以及在何处使用它?也许您可以通过github上的单元测试失败共享一个示例项目?

您的配置看起来正确,我认为这与从Spring注入服务的方式有关,因此事务方面的应用不正确.

不知道这是否对您有帮助:@L_404_2@ 总结

以上是内存溢出为你收集整理的Spring / Neo4J-impermanentGraphDatabase是否与事务注释兼容? 全部内容,希望文章能够帮你解决Spring / Neo4J-impermanentGraphDatabase是否与事务注释兼容? 所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1239954.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存