JPA merge/persist

Asked

Viewed 194 times

0

I have the following structure:

A.class
B.class
C.class
D.class

A.class contains many B.class containing a D.class

C.class contains many D.class containing a B.class

Whereas D.class is persisted in CascadeType.Persist when C.class is persisted.

Scenario: I seek a C.class update a class attribute, for example, add the sequential number and enter a D.class that will be persisted in cascade. For each update operation performed, a D.class is inserted, similar to a log. To accomplish this situation I call the merge method (C.class) that updates the C.class and also persists a D.class.

However, when I do this previous operation, I need to perform a creation of the A.class in the same transaction, so I insert a A.class containing at least one B.class that has relationship to my D.class which was cascaded in the previous situation. The following problem occurs when I do 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 relation could not find that previously persisted object cascading. FinCxaPlanoLcto is the B.class containing a FinCprParcelaLcto which is the object of D.class.

Can anyone tell me what I might be doing to solve this problem?

1 answer

1


I solved the problem with the following situation, when I merged() recovered the object and updated it again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.