将项添加到HashSet <E>时出现NotInTransactionException

Sup*_*miu 6 neo4j spring-data-neo4j spring-data-rest

编辑

由于我现在没有回答并且我打开的github Ticket已经关闭,我将在github上创建一个示例来重现该bug以找出问题所在.一旦问题得到解决,我将在这个问题上添加我自己的答案,以提供真正的解决方案.

首先,我在SDN的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
}
Run Code Online (Sandbox Code Playgroud)

及其存储库接口:

@RepositoryRestResource(collectionResourceRel="player", path="player")
public interface PlayerRepository extends PagingAndSortingRepository<Player, Long> {
}
Run Code Online (Sandbox Code Playgroud)

我使用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
Run Code Online (Sandbox Code Playgroud)

我得到一个例外:

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"
}
Run Code Online (Sandbox Code Playgroud)

要查看完整的堆栈跟踪,请检查问题顶部的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>
Run Code Online (Sandbox Code Playgroud)

编辑:我试图在我的存储库界面上添加@Transactional,它失败并出现同样的错误.

cyb*_*sam 0

[已编辑]

尝试更新 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>
Run Code Online (Sandbox Code Playgroud)