Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Deletion of entity throwing foreign key constraint for unidirectional mapping(Deletion of entity throwing foreign key constraint for unidirectional mapping)
Deletion of entity throwing foreign key constraint for unidirectional mapping [message #1862774] Fri, 29 December 2023 05:59 Go to next message
Sanjana C is currently offline Sanjana CFriend
Messages: 31
Registered: December 2022
Member
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 #1862853 is a reply to message #1862774] Tue, 02 January 2024 15:37 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 60
Registered: December 2021
Member
I don't have a good answer - this can sometimes occur if there are problems with dependencies that cause TopLink/EclipseLink to think there is a circular reference, but I would have thought it would try to null out the references first.

I'd suggest testing with SQL logging turned on and removing the constraint (or delaying all constraints until the end of the transaction) so you can see the SQL that is issued and how it is ordered. This might hint at what is causing the issue and where to look next.

Best Regards,
Chris
Re: Deletion of entity throwing foreign key constraint for unidirectional mapping [message #1862865 is a reply to message #1862853] Wed, 03 January 2024 09:02 Go to previous messageGo to next message
Sanjana C is currently offline Sanjana CFriend
Messages: 31
Registered: December 2022
Member
Hi Chris,

SQL logging is already active and i see it direclty deletes the parent record and no other statements are executed.

I have two versions of code .The one with toplink version deletes the child dependent rows and then parent entity . But somehow eclipselink is not deleting the child objects.

Thanks,
Sanjana

Re: Deletion of entity throwing foreign key constraint for unidirectional mapping [message #1862885 is a reply to message #1862865] Thu, 04 January 2024 10:33 Go to previous messageGo to next message
Sanjana C is currently offline Sanjana CFriend
Messages: 31
Registered: December 2022
Member
Hi Chris,

By altering the constraint with ON DELETE CASCADE in database, the delete of child record happens.

Do we need this option to be enabled for dependent foreingn keys from DB end?

Thanks,
Sanjana

[Updated on: Thu, 04 January 2024 10:39]

Report message to a moderator

Re: Deletion of entity throwing foreign key constraint for unidirectional mapping [message #1862906 is a reply to message #1862885] Fri, 05 January 2024 14:28 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 60
Registered: December 2021
Member
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
Previous Topic:delete operation not happening in child object for relationship mapping
Next Topic:Globally map boolean fields onto smallint in Postgres
Goto Forum:
  


Current Time: Fri Jan 24 00:28:47 GMT 2025

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

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

Back to the top