Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
spring-projects-issues opened this issue Oct 25, 2016 · 2 comments
Assignees
Labels

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Oct 25, 2016

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:

  • DATAGRAPH-918 Neo4jPersistentProperty does not resolve Id property
    ("depends on")
@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 25, 2016

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
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 23, 2017

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 spring-projects/spring-boot#6709.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants