因为我现在没有回答,而且我打开的github Ticket有 已关闭,我将在github上创建一个示例来重现该bug 找到问题所在。一旦问题得到解决,我将添加我的 自己对这个问题的回答提供了一个真正的解决方案。
首先,我将此报告为issue on SDN's Github。
无论如何,我在这里发布我的问题,看看是否有人有解决方案。
所以,我有一个玩家模型:
@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的朋友:
curl -i -X POST -H 'Content-type: text/uri-list' -d 'localhost:8080/api/player/1' http://localhost:8080/api/player/0/friends
我得到一个例外:
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,它失败并出现同样的错误。