user4569126
user4569126

Reputation: 23

MappingException: Error mapping GraphModel to instance

I'm trying to follow the new Cineasts app with SDN 4.0.0.M1 and SpringBoot to learn Spring and Neo4j but I have an error when I try to access the movie url with curl http://localhost:8080/movies

MappingException: Error mapping GraphModel to instance

I implemented the minimum to get something working so the code is simple but I probably forgot something

the movie class

 @NodeEntity
    public class Movie {
    @GraphId
    private Long nodeId;

    private String id;
    private String title;

    public Movie() {
    }

    public Movie(String id, String title) {
        this.id = id;
        this.title = title;
    }
}

the associated MovieRepository is empty at the moment

public interface MovieRepository extends GraphRepository<Movie> {
}

the MovieController

@Autowired
private MovieRepository movieRepository;
@Autowired
private Session session;

@RequestMapping(value = "/movies/{id}", method = RequestMethod.GET, headers = "Accept=application/json")
public
@ResponseBody
Movie getMovie(@PathVariable String id) {
    return IteratorUtil.firstOrNull(findMovieByProperty("id", id));
}

public Iterable<Movie> findMovieByProperty(String propertyName, Object propertyValue) {
    return session.loadByProperty(Movie.class, new Property(propertyName, propertyValue));
}

and the main class with database connection

@SpringBootApplication
@EnableNeo4jRepositories("cineasts.repository")
@EnableTransactionManagement
public class CineastsApplication extends Neo4jConfiguration {

    public static final int NEO4J_PORT = 7474;

    @Bean
    public Neo4jServer neo4jServer() {
        return new RemoteServer("http://localhost:" + NEO4J_PORT);
    }

    @Override
    public SessionFactory getSessionFactory() {
        return new SessionFactory("org.neo4j.cineasts.domain");
    }

    @Override
    @Bean
    @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
    public Session getSession() throws Exception {
        return super.getSession();
    }

    public static void main(String[] args) {
        SpringApplication.run(CineastsApplication.class, args);
    }
}

I started Neo4j and added one record with Neo4j browser

CREATE (m:Movie {id:1, name:'The Matrix'}) return m

when I go to localhost:8080 I can see the json response

{
  "_links" : {
    "movies" : {
      "href" : "http://localhost:8080/movies"
    },
    "profile" : {
      "href" : "http://localhost:8080/alps"
    }
}

but it fails to display the movies or http://localhost:8080/movies/1 record I just created. Any idea to fix this or get a more relevant message?

Thanks!

Upvotes: 0

Views: 4153

Answers (1)

Luanne
Luanne

Reputation: 19373

The problem could be the fact that your entity definition does not match that of the node you've created. The Movie class defines a property id of data type String, and a property title of type String.

The Cypher you used however

CREATE (m:Movie {id:1, name:'The Matrix'}) return m

creates a node with a number id instead of a String id and a name property instead of a title property.

Changing the above to

CREATE (m:Movie {id:'1', title:'The Matrix'}) return m

should fix it.

Upvotes: 2

Related Questions