Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Merge trying to delete an existing entry while trying to add a new entry(Merge trying to delete an existing entry while trying to add a new entry)
Merge trying to delete an existing entry while trying to add a new entry [message #1822457] Sat, 07 March 2020 04:50 Go to next message
Neeraj Sachdeva is currently offline Neeraj SachdevaFriend
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.
Re: Merge trying to delete an existing entry while trying to add a new entry [message #1822544 is a reply to message #1822457] Mon, 09 March 2020 16:27 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
You have orphanRemoval = true which has me suspecting that you are nulling out or removing the relationship to the RW that is getting deleted. Why are you setting this?
Check that what you are merging in has everything fully set, as merging in an incomplete collection with this setting on it would cause everything else in the collection to be deleted from the database.

Previous Topic:EclipseLink throws JPQLException on using SELECT ... AS in a constructor expression
Next Topic:Multitenant per table and native query
Goto Forum:
  


Current Time: Fri Apr 26 13:30:39 GMT 2024

Powered by FUDForum. Page generated in 0.03665 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top