Deletion of entity throwing foreign key constraint for unidirectional mapping [message #1862774] |
Fri, 29 December 2023 00:59  |
Eclipse User |
|
|
|
Hi ,
I have a unidirection one-to-one mapping as below . When deleting the parent entity, eclipselink throws error saying foreign key constraint child object found.
@OneToOne(targetEntity = SystemeImpl.class,fetch = FetchType.LAZY,orphanRemoval = true,cascade = CascadeType.ALL)
@JoinColumn(name="SY_ID", referencedColumnName = "id")
private ValueHolderInterface systeme;
public Clientsysteme getsysteme() {
return (this.systeme != null) ? (Systeme) this.systeme.getValue() : null;
}
public void setSysteme(Systeme systeme) {
SystemeImpl target = (SystemeImpl) systeme;
this.setSystemeImpl((SystemeImpl)systeme);
}
public void setSystemeImpl(SystemeImpl systeme) {
if (systeme != null) {
if (this.systeme != null) {
this.systeme.setValue(systeme);
} else {
this.systeme = new ValueHolder(systeme);
}
} else {
if (this.systeme != null) {
this.systeme.setValue(null);
}
}
}
When deleting the record in system table, it should automatically delete the records in child table but even after configuring cascade, orphan removal , error is thrown.
Error:
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-02292: Integritäts-Constraint (FAN_SY_FK) violation - child record found.
Could you please suggest me whether do i need to configure anything else ?
Thanks,
Sanjana
|
|
|
|
|
|
Re: Deletion of entity throwing foreign key constraint for unidirectional mapping [message #1862906 is a reply to message #1862885] |
Fri, 05 January 2024 09:28  |
Eclipse User |
|
|
|
If EclipseLink isn't coming back and trying to delete the child after (maybe try another entityManager.flush()), you'll have to check that you don't have any other references to the child entity somewhere that might have a cascade merge/persist setting. You should not need to use the ON DELETE CASCADE option, but it is more efficient than having the application issue another statement, so you might want to anyway - try to set @CascadeOnDelete on your mapping so EclipseLink is aware of it. Just be aware that if EclipseLink isn't doing the delete, it might not be clearing the Child entity from the cache either
Regards,
Chris
|
|
|
Powered by
FUDForum. Page generated in 0.07698 seconds