Cascade Issue [message #1852197] |
Wed, 04 May 2022 10:32  |
Eclipse User |
|
|
|
Below is the parent table dto which has requestStatus as IN_PROGRESS which gets updated to DONE on updating child table as below:
@OneToOne(cascade = CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="vendorServiceability", targetEntity=ServiceabilityStatusDTO.class)
private IServiceabilityStatus serviceabilityStatus;
@Column(name="REQUEST_STATUS", length=15)
private String requestStatus;
Below is the child table dto which insert record and update requestStatus to DONE in parent table dto
@OneToOne(cascade={CascadeType.PERSIST,CascadeType.MERGE},fetch=FetchType.EAGER,targetEntity=VendorServiceabilityDTO.class)
@JoinColumn(name="SERVICEABILITY_KEY", unique=true)
private IVendorServiceability vendorServiceability;
We checked when running for 100 products, for each product while saving child table, it updates parent table requestStatus to Done and again it updates to IN_PROGRESS from another thread. So, final status is like out of 100, around 50 are marked as Done and remaining as InProgress.
We tried using flush and clear entitymanager but issue still persist.
please suggest.
|
|
|
Re: Cascade Issue [message #1854241 is a reply to message #1852197] |
Mon, 08 August 2022 14:08  |
Eclipse User |
|
|
|
What is 'it' in the context of "it updates parent table requestStatus to Done and again it updates to IN_PROGRESS from another thread. " Does this mean in a single transaction you see the state change from one state and then back again? It isn't clear what product is, as you mention a parent and child, but then switch to using product in your description; it would help to show an example in code of what you are doing, and what state you expect vs what state is actually occurring.
From just guessing, this appears to be a non-deterministic problem that you are experiencing; I'd guess further you are calling merge on an object model (parent) that has bidirectional relationships but with an incomplete/inaccurate graph built, such that parent1 -> child1 -> parent1'. This might allow the state of the parent as referenced by the child to be inconsistent with the state of the parent instance that references the child, and what gets into the database then depends on how the mappings are processed by merge calls. I'd suggest you look closely at the object model being worked on and how it is built in your threads (especially of JSON serialization is used) to ensure that the object graph maintains identity before passing it into JPA merge operations, and that the cascade operations on references are appropriate.
Best Regards,
Chris
|
|
|
Powered by
FUDForum. Page generated in 0.09788 seconds