Hi,
sorry if this is a recurrent subject, but reading the Hibernate Docs and searching in the forum I didn't found an answer, or I'm not knowing how to search!
Is there a way to let Hibernate automatically deals with the synchronization between class members of ManyToOne and OneToMany?
For example:
Code:
@Entity
class Parent
{
...
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
private List<Child> childList;
...
}
@Entity
class Child
{
...
@ManyToOne
private Parent parent;
...
}
When I do:
Code:
Parent parent = new Parent();
Child child = new Child();
child.setParent(parent);
What I want is the childList of the parent to be automatically synchronized, so if I do:
parent.getChildList() the previously child will be in the list.
Is this possible? Or I need to manually deal with this, removing and adding the child from the parent List each time the child's parent changes?
Note: I know that if I load the parent object in another hibernate session, the collection will be proper loaded, but what I need is this synchronization happening inside the same session and without calling flush() refresh(). What I need is my business logic working the same way, independently if I call it in different sessions or in the same session.
Thanks,
Rafael Ceravolo