I have A object which has a @ManyToOne to a B object.
From a different JVM I receive a transient A which references a detached B.
If I now persist A:
Code:
entityManager.persist(a);
then a is in the persistence context, but a.getB() is not.
This leads to problems. Does the spec allow to have a persistent object refer to a detached object?
Is there a specific reason why hibernate doesn't simply change the a.getB() with a proxy of B (or a persistent instance of B)?
Note that I don't want PERSIST/MERGE cascading from A to B.
If I now query that A (and it's B) from the database, like this:
Code:
A refreshedA = entityManager.createQuery("from A a left join fetch a.b left join fetch b.c where a.id = " + a.getId()).getSingleResult();
Then a.getB() is still the detached object (it's not in the persistent context) and even worse, the a.getB().getC() isn't loaded (even though I explicitly asked to fetch it in the query).
Thanks for any and all help.