This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

My reading of the docs is that these connections will be automatically created by the bit-twiddling under the covers. So that when an Item is added to the items attribute of Layer, a corisponding relationship should be created from Item.layers back to the Layer the Item was added to. But this is not happening. The following test fails:

I would save the Item first. so put template.save(item1) before the two repository.save calls.

I am thinking that the repo calls to save can't create the relationship on an item that isn't a node in the db yet.

Actually, more of a problem is how is the item1 supposed to automatically have two objects added to its set magically. Who would call it based on your code. No one did. This is just Java that caused that, nothing about neo4j or Spring Data neo4j. Now if you do a find/query after you have saved your objects, then the item will have its layers.

In say JPA, you have to make sure you set both sides in your code if you want it to work without querying the database to refresh the objects. I think that would be the same here.

Hope that helps.

Mark

Comment

To your first point, about saveing item1, it is saved by the time it is added to the layers. So that's not relevent.

As to your second point, about adding the relations, the Neo4j documentation very clearly states that it does in the AspectJ/bit-twiddled code. It would kind of have to do this too, as otherwise, there would be know way in code of handleing this, without bringing all of the contents of the relationship into memory, negating the lazy-loading stratagy. You couldn't do 'add to collection if not present'.