[Hibernate] managing multiple detached objects that represent the same database row
posted 6 years ago
Suppose I have class Parent and a class Child
First I retrieve a Parent from the database with all its children.
I close my session, so now I have 1 Parent with all its children as detached objects.
I now start a second session and only retrieve 1 child. But that child's parent is the same parent I retrived from the first session. So that child is also in the list of children I got from my first DB transaction.
But the problem is: they are both different java instances. So if I change the parent object I got from the first transaction, or I change the child from the second transaction, then I have 2 objects that represent the same row in DB but with different values.
Is there a way to solve/manage these kind of things?