Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-02-2021 06:24 AM
I've been using Spring Data Neo4j 6.x for a project but have now got to a point where it looks like I need to do a .save() with a specific depth, given that child relationships are being nuked on saves a few levels up.
While refactoring some of the DTO objects I noticed that org/neo4j/ogm/metadata/ClassInfo.java:isPrimaryIndexField()
is checking for existence of @org.neo4j.ogm.annotation.Id
; of course given I've been using Spring Boot Data Neo4j all my classes have been annotated with @org.springframework.data.neo4j.core.schema.Id
so this check fails.
What's the accepted / expected pattern then, if I'm persisting objects via both SBD and OGM do I add both SBD and OGM @Id
annotations to the graph Id field?
Edit: I should add it does in fact work, but it just looks wrong to have a field with duplicate @Id
and @GeneratedValue
annotations from SBD and OGM, so I'm wondering if I've gone down the wrong route that's all ... example of one of the graph models here, corresponding OGM persistence performed here, vanilla SBD persistence here.
Edit 2: Spoke too soon, morning's refactoring has gone to pot a bit given I'm now seeing duplicate relationships as @Start/EndNode
items are being added by OGM and @TargetNode
is being used by SDN. ... feels like I should try and remove OGM and try figure out a different way of committing objects with a specific depth. Will leave above links to specific commits.
05-02-2021 08:57 AM
Update: Replying to myself because as a new user I can only post 5 links per message;
Hopefully the following image makes sense: 'awardNode' has 1..n 'organisationNode' nodes via a @RelationshipProperties object. Each orgNode has 1..n orgPersons - populated in the orgNode method instance because I've explicitly pulled them back in the that query but null in the awardNode
(because I didn't pull them back in that query).
It looks like the saving of the new awardNode
object (with empty orgPersons
) results in all relationships being deleted (even though I thought setting the list to null meant the relationships wouldn't be updated / modified as compared to it explicitly being an empty list?).
So the question is - with SDN 6.x and without a @Depth
parameter, is there any way of updating that awardNode
instance without it then traversing through and nuking all the orgPersons
relationships? And without me having to pull back literally every single node at infinite depth.
tl;dr (summarising both posts):
Is it bad practise to use OGM + Spring Data Neo4j in the same project (and therefore duplicating annotations if classes are shared by OGM and SDN)
Is there any way around the new domain-type modelling in SDN 6.x that forces me to traverse through all objects + populate them all before committing any changes (as compared to performing a save with depth as via OGM)?
05-03-2021 08:08 AM
With SDN 6+ there is no need of having Neo4j-OGM anywhere in your application.
Starting with SDN 6.1 it is possible to use the projections also for saving. Since the documentation does not explicitly talk about this, here is a link to one of our integration tests for this feature: spring-data-neo4j/Neo4jTemplateIT.java at 6.1.x · spring-projects/spring-data-neo4j · GitHub
05-04-2021 02:46 AM
You are a legend, thank you - this is exactly what I'm looking for. I'll bump it up to 6.1.x and start playing with it immediately.
All the sessions of the conference are now available online