I have the following structure:
A.class
B.class
C.class
D.class
A.class
contains many B.class
that contains D.class
C.class
contains many D.class
that contains B.class
Being D.class
is persisted in CascadeType.Persist
when C.class
is persisted.
Scenario: I search for a C.class
I update an attribute of the class, for example, add the sequential number and I insert a D.class
that will be persisted in cascade. For each update operation performed, a D.class
is entered, similar to a log.
To do this I call the merge ( C.class
) method that updates the C.class
and also persists a D.class
.
However, when I do this previous operation, I need to make a A.class
creation in the same transaction, so I make an insertion of a A.class
that contains at least a B.class
that is related to my D.class
that was cascaded in the previous situation.
The following problem occurs when I EntityManager.persist(A.class)
:
Caused by: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : br.com.criabyte.model.aplicacao.financeiro.cxa.FinCxaPlanoLcto.finCprParcelaLcto -> br.com.criabyte.model.aplicacao.financeiro.cpr.FinCprParcelaLcto
That is, the relationship could not find that object previously persisted in cascade.
FinCxaPlanoLcto
is the B.class
that contains a FinCprParcelaLcto
that is the D.class
object.
Does anyone know what to do to solve this problem?