NotInTransactionException when adding an item to a HashSet <E>

EDIT

Since I did not receive a response at the moment, and the github ticket open that I opened was closed, I will create an example on github to reproduce the error finding the problem. Once the problem is fixed, I will add my own answer to this question to provide a real solution.

First of all, I reported this as a problem on the Github SDN .

Anyway, I post my problem here to find out if anyone has a solution.

So, I have one player model:

@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 } 

and its repository interface:

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

I created two players using POST requests and confirmed that they were actually created using GET.

Then I want to add player 0 as a friend of player 1:

 curl -i -X POST -H 'Content-type: text/uri-list' -d 'localhost:8080/api/player/1' http://localhost:8080/api/player/0/friends 

And I get an 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" } 

To see the full stack trace, check out the Github link at the top of the question, it's too long to read here.

Just in case, here is my 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> 

EDIT: I tried adding @Transactional to my repository interface, it failed with the same error.

+6
source share
1 answer

[Changed]

Try updating your POM file to use version 1.3.0.RELEASE in the Spring structure. Something like that:

 <?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> 
0
source

All Articles