I have a data model like this:
import org.neo4j.ogm.annotation.Id
import org.neo4j.ogm.annotation.NodeEntity
@NodeEntity
class Parent {
@Id lateinit var name: String
constructor(name: String) { this.name = name }
lateinit var hasChildren: MutableSet<Child>
}
@NodeEntity
class Child {
@Id lateinit var name: String
constructor(name: String) { this.name = name }
lateinit var friendOf: Child
}
The following code breaks the "friend_of" relation and I can't figure out why.
sessionFactory.openSession()?.run {
purgeDatabase()
var parent1 = Parent("parent1")
save(parent1)
var parent2 = Parent("parent2")
save(parent2)
var child1 = Child("child1")
parent1.hasChildren = mutableSetOf(child1)
save(parent1)
var child2 = Child("child2")
parent2.hasChildren = mutableSetOf(child2)
save(parent2)
child1.friendOf = child2
save(child1)
//Everything is good until this point. child1-[friend_of]->child2
parent1 = load(Parent::class.java, "parent1")
save(parent1)
//Loading/saving parent1 does not break anything. All good until this point..
parent2 = load(Parent::class.java, "parent2") //tried passing depth = 2 as well
save(parent2) //tried passing depth = 2 as well
//loading/saving parent2 breaks and deletes the "friend_of" relation between child1 and child2
}
I have tried various depth options in load/save but no success. I have also tried clearing session and starting new transaction for each write with no luck.
Why does a reload/resave of "parent1" does not break the relation, but "parent2" breaks it?