Merge trying to delete an existing entry while trying to add a new entry [message #1822457] |
Sat, 07 March 2020 04:50 |
Neeraj Sachdeva Messages: 1 Registered: March 2020 |
Junior Member |
|
|
Hi Team,
Class Structure & relationship:
```
@Entity
public class WIR implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "reportWorkSequence")
@Column(name = "R_W_I")
private Long rwi;
@OneToMany(mappedBy = "rw", cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, orphanRemoval = true)
private List<RM> rmList;
```
```
@Entity
public class RM implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private RMPK id;
@ManyToOne
@JoinColumn(name = "R_W_I", insertable = false, updatable = false)
private WIR rw;
```
````
class RMPK {
long rwid;
....
.... //other fields
```
Consider above two tables & there is a 3rd table DRM which has
a) PK consisting of all fields under RMPK + one more field of some other table.
b) FK to RM
Background:
I've an class (call it Subject) which consists of List of RW, so whenever there is new RW that needs to be saved, whole "Subject" instance is passed to merge method.
I did not face any issue until this new 3rd table came into existence DRM.
Problem Statement:
1. A new RW (id=10) (which contains an 2 RM entry as well) is persisted by calling merge method on Subject instance. An entry is also saved in DRM table having this rwid as one of the PK column value.
2. Another RW(id=11) (which may contain same or different RM as well) is tried to be persisted again by calling merge method on Subject instance
At step 2, eclipseLink is trying to delete RW with id=10 first but because it has a child entry in DRM table, so it gives below error
[WARNING ] CWWJP9991W: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-02292: integrity constraint (EOP_OWN.FK_DFCTRPTMEAS_RPTMEAS) violated - child record found
Error Code: 2292
Call: DELETE FROM <schema_name>.R_M WHERE (((((A_C = ?) AND (A_S_T_C = ?)) AND (R_W_I = ?)) AND (O_S_N_I = ?)) AND (W_E_T_C = ?))
bind => [5 parameters bound]
Query: DeleteObjectQuery(com.csx.ewos.data.entity.RM@691214ad)
[ERROR ] WTRN0074E: Exception caught from before_completion synchronization operation: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-02292: integrity constraint (EOP_OWN.FK_DFCTRPTMEAS_RPTMEAS) violated - child record found
I'm not sure why this delete operation is happening on existing RW when I'm actually trying to add another RW.
NOTE:
1. Both the records are unique in all manners.
2. All PK has equals & hashcode autogenerated methods.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03551 seconds