Question

I am having a problem when updating/merging an entity A which has a reference to another entity B. A also has a reference to an entity C.

I create a new instance of the entity A from a domain object. Also from this domain object I use the ids to get B and C by using entityManager.getReference(<class>, <id>). I call entityManager.merge and entityManager.flush(). So far all is good, the values of both B and C are present in A. When I after the flush do a entityManager.refresh(A), the B is cleared(null), but the C is still there.

I run sql queries to verify that the value is there before the update. After the flush the FK to B is cleared, so when the refresh is called it discovers this.

I do not know what to look for here. Might it be something with how my entities are defined? Persistence-xml? Any tips are much appreciated!

EDIT: The value of B is only cleared if I do not change the reference. If I change the reference of B to B', then it is updated correctly

Was it helpful?

Solution

The question did not show the entire context of where I was experiencing the problem. The entity A which had a reference to B, also had the foreign key field in it. This foreign key field was always null, so setting the entity reference had no effect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top