Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-17-2019 10:10 PM
Consider the following code:
@NodeEntity
public class Entity {
...
}
@RelationshipEntity
public class RelationInstance{
@StartNode
Entity src;
@EndNode
Entity dst;
...
}
Entity en1 = new Entity();
session.save(en1);
Entity en2 = new Entity(); // en2 is not saved.
session.save(new RelationInstance(en1, en2), 0)
I expect that the code throws an exception because en2 is not persisted and we call the second save with a depth parameter of 0. But it seems that it does not throw an exception and saves en2. Why is that? How should I make it throw an exception?
08-28-2019 04:26 PM
Your code cannot compile, you cannot call the two classes the same.
Can you try to save en2 first.
You are also missing a relationship-type in the annotation.
08-31-2019 09:49 PM
It was a mistake. I changed the second class name. However, my question still exists.
09-02-2019 04:39 PM
It cascades the save.
If you want an exception you need to check for nulls in your relationship-entity in a pre-save.
09-02-2019 09:29 PM
So what is the purpose of the depth parameter? Shouldn't the "save" not save the related objects when a depth of 0 is mentioned?
09-03-2019 06:07 AM
Ah sorry, I missed that, good question. I think 0 is infinite. And 1 is one level.
But I'd leave that to @gerrit.meier who's more knowledgable than me on this.
09-03-2019 11:45 PM
here mentions that "A depth of 0 will persist only the properties of the specified entity to the database."
09-03-2019 11:47 PM
Also, it seems that not only it saves the entity if it does not exist, but also it updates it if it previously exists. Seems to ignore the depth!
09-04-2019 08:13 AM
For relationship-centric saves the relationship and the nodes will get persisted.
This is needed because the RelationshipEntity
does not get identified just by its own id but also the nodes that the relationship connects.
You are right, the documentation is a little bit vague and should say NodeEntity
instead of just entity.
12-09-2019 09:52 PM
but how can we get relationship with custom query?
All the sessions of the conference are now available online