gpt4 book ai didi

neo4j - 将项目添加到 HashSet 时出现 NotInTransactionException

转载 作者:行者123 更新时间:2023-12-04 16:08:02 27 4
gpt4 key购买 nike

编辑

Since I got no answer at the moment and the github Ticket I opened hasbeen closed, I'll create an example on github to reproduce the bug tofind what's the problem. Once the problem will be fixed, I'll add myown answer to this question to provide a real solution.


首先,我将此报告为 issue on SDN's Github .
无论如何,我在这里发布我的问题,看看是否有人有解决方案。
所以,我有一个 Player 模型:
@NodeEntity
public class Player {

@GraphId Long id;
String name;

String email;

@Transient
String password;

int elo = 1200;

@RelatedTo(type="FRIEND_WITH", direction = Direction.BOTH)
Set<Player> friends = new HashSet<Player>();

//After this I have Getters and Setters
//no need to paste them all I guess
}
及其存储库界面:
@RepositoryRestResource(collectionResourceRel="player", path="player")
public interface PlayerRepository extends PagingAndSortingRepository<Player, Long> {
}
我使用 POST 请求创建了两个播放器,并验证它们确实是使用 GET 创建的。
然后我想将玩家 0 添加为玩家 1 的 friend :
curl -i -X POST -H 'Content-type: text/uri-list' -d 'localhost:8080/api/player/1' http://localhost:8080/api/player/0/friends
我得到一个异常(exception):
HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Content-Type: application/hal+json;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 09 Nov 2015 16:20:24 GMT
Connection: close

{
"timestamp" : "2015-11-09T16:20:24.844+0000",
"status" : 500,
"error" : "Internal Server Error",
"exception" : "org.neo4j.graphdb.NotInTransactionException",
"message" : "No message available",
"path" : "/api/player/0/friends"
}
要查看完整的堆栈跟踪,请查看问题顶部的 Github 链接,此处太长而无法阅读。
以防万一,这是我的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.afkgames</groupId>
<artifactId>api-rest-sdn</artifactId>
<version>0.1.0</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
<start-class>api.Bootstrap</start-class>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>neo4j</id>
<name>Neo4j</name>
<url>http://m2.neo4j.org/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
</pluginRepository>
</pluginRepositories>

</project>
编辑:
我试图在我的存储库界面上添加 @Transactional,但失败并出现相同的错误。

最佳答案

[编辑]

尝试更新 POM 文件以使用 Spring 框架的 1.3.0.RELEASE 版本。像这样的东西:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.afkgames</groupId>
<artifactId>api-rest-sdn</artifactId>
<version>0.1.0</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
<start-class>api.Bootstrap</start-class>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
<repository>
<id>neo4j</id>
<name>Neo4j</name>
<url>http://m2.neo4j.org/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>

</project>

关于neo4j - 将项目添加到 HashSet<E> 时出现 NotInTransactionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33628210/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com