spring-projects / spring-data-rest

Simplifies building hypermedia-driven REST web services on top of Spring Data repositories
https://spring.io/projects/spring-data-rest
Apache License 2.0
919 stars 563 forks source link

Getting error "Id must be assignable to Serializable" with simple Neo4j repository [DATAREST-928] #1291

Open spring-projects-issues opened 8 years ago

spring-projects-issues commented 8 years ago

Florian opened DATAREST-928 and commented

I'am building a simple Spring Boot app with Spring Data Rest and Neo4j. I followed the instruction guide here: https://spring.io/guides/gs/accessing-neo4j-data-rest/

Here is my pom.xml file:


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         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>

    <artifactId>my-service</artifactId>
    <packaging>jar</packaging>

    <name>my-service</name>
    <description>my-service</description>

    <properties>
        <main.basedir>${basedir}/../..</main.basedir>
        <thymeleaf.version>3.0.0.RELEASE</thymeleaf.version>
        <thymeleaf-layout-dialect.version>2.0.0</thymeleaf-layout-dialect.version>
        <jackson.version>2.7.0</jackson.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-neo4j</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Here is my entity TreeComponent:


package myservice.entities;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;
import org.neo4j.ogm.annotation.typeconversion.Convert;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

@NodeEntity
@JsonIgnoreProperties(ignoreUnknown = true)
public class TreeComponent implements Serializable {

    @GraphId
    private Long id;
    @NotNull
    private String source;
    private String name;
    @Convert(DataConverter.class)
    private JsonNode data = JsonNodeFactory.instance.objectNode();
    private String urlPart;
    private String content;

    @Relationship
    public Set<TreeComponent> children = new HashSet<>();

    public TreeComponent() {
    }

    public Set<TreeComponent> getChildren() {
        return children;
    }

    public void setChildren(Set<TreeComponent> children) {
        this.children = children;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public JsonNode getData() {
        return this.data;
    }

    public void setData(JsonNode data) {
        this.data = data;
    }

    public String getUrlPart() {
        return urlPart;
    }

    public void setUrlPart(String urlPart) {
        this.urlPart = urlPart;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

The repository class TreeComponentRepository:


package myservice.rest.repositories;

import myservice.entities.TreeComponent;
import org.springframework.data.neo4j.repository.GraphRepository;

public interface TreeComponentRepository extends GraphRepository<TreeComponent> {
}

Finally, the annotations used on the Spring boot app class:

@SpringBootApplication
@EnableDiscoveryClient
@EnableNeo4jRepositories

Everything works fine, I even got my data in the Neo4j database (+with IDs+). Unfortunately, I've got the following error when accessing my data through the rest API (http://localhost:8861/api/treeComponents):


cause: null,
message: "Id must be assignable to Serializable! Object of class [null] must be an instance of interface java.io.Serializable"

Is it a bug or am i missing something ?

Thanks for the help.


Affects: 2.5.4 (Hopper SR4)

Issue Links:

spring-projects-issues commented 8 years ago

Mark Paluch commented

That issue is caused by DATAGRAPH-918, more specific by spring-data-neo4j Version 4.1.3 and newer. Please use spring-data-neo4j Version 4.1.1 or 4.1.2 as workaround

spring-projects-issues commented 7 years ago

Mark Angrish commented

I've just created a test with Spring Boot 1.5, Spring Data (Ingalls) and there seems to be no problems any more.

This was probably fixed by the Neo4j repositories now supporting Serializable ID's.

See: https://jira.spring.io/browse/DATAGRAPH-955 and https://github.com/spring-projects/spring-boot/issues/6709.

Please try again with the new versions and let me know how you get on