I am using JPA 2 with Hibernate 3.6.8 as an implementation.
Say we have an entity Foo
@Entity
public class Foo {
....
@OneToOne
private Bar bar;
....
}
I need to separate the entire graph of the object from the session, and when I do entityManager.detach(foo), I was surprised that I barremained attached, that IMO is quite counterintuitive.
Looking at the documentation on EntityManager, it seems like this is an expected case, as it does not mention anything about associations / children:
Remove this object from the persistence context, as a result of which the managed object becomes disconnected. Unflushed changes made to the object, if any (including deleting the object), will not be synchronized with the database. Objects that previously referenced a single object will continue to reference it.
entityManager.detach(foo.getBar()) , , , - , , .
, ?