EDIT : A sample project is available on github .
I use Neo4J (a break database hosted in grapheneDb) and Spring Data in our backend project.
<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringCypherRestGraphDatabase">
I have a simple one-to-many relationship between two objects: User and Stay .
EDIT . I thought this did not apply to the problem, but after looking at a similar problem in SDN4, I think I need to update the question (there is a base class @NodeEntity , and both objects extend this base class).
@NodeEntity public abstract class BasicNodeEntity implements Serializable { @GraphId private Long nodeId; } public class User extends BasicNodeEntity { @RelatedTo(type = "HAS_STAY", direction = Direction.OUTGOING) Set<Stay> stays; public void addStay(Stay stay) { stays.add(stay); } } public class Stay extends BasicNodeEntity { @RelatedTo(type = "HAS_STAY", direction = Direction.INCOMING) User user; }
I can no longer stay in one place. The first stay that I add to the user is saved correctly, but only the first. The following additions are not saved, and I always get the first one.
The method that I use to create a new stay:
@Autowired Neo4jOperations template; @Transactional private void createStay(Stay stay, User user) throws Exception { stay = template.save(stay); user.addStay(stay); template.save(user);
EDIT . User changed correctly restored using UserRepository .
public interface UserRepositoryCustom {} public interface UserRepository extends GraphRepository<User>, UserRepositoryCustom { User findById(String id); } User user = userRepository.findById(userId);
NOTE. I also tried saving through the repository interface instead of Neo4jTemplate, but I have the same problem.
Both objects are stored correctly in the neo4j database, this is a storage problem.
I think this should be pretty easy, so I probably missed something.
Any help would be greatly appreciated.
Relevant Versions:
<spring.version>4.0.5.RELEASE</spring.version> <spring-data-neo4j.version>3.3.2.RELEASE</spring-data-neo4j.version>
There is another SO question with a very similar problem, but no answer so far.