cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Struggling to understand the Spring Java Driver--Entities not saving with no errors

I created some entities and tried to save them to the database. Some of them saved, some of them didn't. But no errors were thrown. I'm going to try to put together an example.

The Person GOES_TO a Place . A Thing is OWNED_BY a Person . I get a collection of people, and call saveAll(people) and the Places are in the DB, but the People are not. Then I get a collection of Things from each person and the Things are saved in the DB, but still no People.

Here are some classes:

NodeEntity //put an @ here (new user limitation)
public class Person {
    Id // put an @ here
    private Long id;
    private String name;
    Relationship(type = "GOES_TO") // put an @ here
    private Place place;
    // ... getters and setters here
}
NodeEntity // put an @ here
public class Place {
    Id // put an @ here
    private Long id;
    private String name;
    Relationship(type = "IN") // put an @ here
    private Country country; // note that this value is always null in this test
    // ... getters and setters here
}
NodeEntity // put an @ here
public class Thing {
    Id // put an @ here
    private String thingId; // note the ID is different, not sure if that matters
    private String name;
    Relationship(type = "OWNED_BY") // put an @ here
    private Person person;
    // ... getters and setters here
}

Pretty simple right? I create standard Spring repositories for each entity like this:

public interface PersonRepository extends Neo4jRepository<Person, Long> {
}

Then I go to save some Person objects. With a collection of Persons, I see that the Places that they have inside them are being created in the database, but the Persons are not. Then, I create a bunch of Things, attaching the relevant Person to them. This time the Things are created, but still no Persons are created. No error is being thrown, there just aren't any nodes.

P.S. this is a minimal example. I'm not 100% sure yet if it reproduces the error, but I'll work on an example of that. and update this post.

2 REPLIES 2

Yes a minimal example that runs and fails would be good, with the creation of the entities and how you run that transactionally too.

I managed to make it work. In summary, for some reason Neo4J was not liking that my IDs were Java Longs rather than Strings. When I changed the ID for the Person class to String, it started working. It wasn't throwing errors, and there weren't type issues, so I have no idea what was wrong.