Skip to content
Advertisement

Problem in updating the entity with unidirectional @ManyToOne relation

I have two entities as below and the main problem is when I want to update the AccountRequestStatus entity. I save the integer enum code of AccountRequestStatusEnum in the database to persist the AcountRequest status in the whole application.

AccountRequestStatusEnum

JavaScript

AccountRequest

JavaScript

AccountRequestStatus

JavaScript

The first time that an account request comes from MQ my to application, I save the initial code of AccountRequestStatusEnum in service like below. This status persists properly and there is no problem, but when I want to update the AccountRequestStatus and add a new success code of AccountRequestStatusEnum (in another service) it won’t be saved in DB.

This is the first service that is called after receiving the account request and saving the initial code.

JavaScript

This is the second service that should save the success code of AccountRequestStatus.

JavaScript

AccountRequestStatusServiceImpl

JavaScript

AccountRequestDto

JavaScript

AccountRequestStatusDto

JavaScript

AccountRequestStatusMapper

JavaScript

Advertisement

Answer

I fixed the issue by adding the saveSuccessfulAccountRequest to the AccountRequestServiceImpl service as below, and calling the saveSuccessfulAccountRequest in SyncLegacyAccountServiceImpl service. The main point of this approach is that saveSuccessfulAccountRequest should have propagation = Propagation.REQUIRES_NEW, without this, it does not work!!! But actually, I am not sure why it should be propagation = Propagation.REQUIRES_NEW :)))

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement