Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Delete operation calling update statement to make foreign key field to null(Delete operation calling update statement to make foreign key field to null)
Delete operation calling update statement to make foreign key field to null [message #1863273] Mon, 22 January 2024 11:05 Go to next message
Sanjana C is currently offline Sanjana CFriend
Messages: 31
Registered: December 2022
Member
Hi Team,

Iam using eclipselink 2.7.6 version

I have already seen this issue someone addressing but there was no response.

I am facing below error while there is a delete operation .The eclipselink tries to update the foreign key field with null before comming the delete .
But i have not null contraint on the column which results in the issue.

Internal Exception: java.sql.SQLException: ORA-01407: Unable to update ("KPN_ENT"."KPN_ID") to NULL

Error Code: 1407
Call: UPDATE KPN_ENT SET KPN_ID = ?, LOCKING_TIMESTAMP = ? WHERE ((ID = ?) AND (LOCKING_TIMESTAMP = ?))
bind => [null, 2024-01-22 11:42:08.853117, 200011, 2024-01-22 11:41:57.923187]
Query: UpdateObjectQuery(KPN_Ent@6a16ee0d)

In boths tables , it has one-to-one relationship.

Could you please suggest me on this.
Re: Delete operation calling update statement to make foreign key field to null [message #1863288 is a reply to message #1863273] Tue, 23 January 2024 16:23 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 54
Registered: December 2021
Member
Maybe show the mapping and the EclipseLink version you are using. When in doubt - try the latest - I found https://bugs.eclipse.org/bugs/show_bug.cgi?id=391279 which seems to involve inserts with unidirectional 1:M mappings, but without knowing what you are doing or seeing, this might be it.

Though when EclipseLink finds a circular reference, it has no choice in some cases but to null out foreign keys when removing (or leave them blank on inserts/updates and come back to update them later too). It now should try to respect non-null constraints if it knows about them, but I haven't tested it myself. See https://www.eclipse.org/forums/index.php/t/298970/ for description on similar issues and where it would null foreign keys.


Best Regards,
Chris
Re: Delete operation calling update statement to make foreign key field to null [message #1863295 is a reply to message #1863288] Wed, 24 January 2024 11:16 Go to previous messageGo to next message
Sanjana C is currently offline Sanjana CFriend
Messages: 31
Registered: December 2022
Member
Hi Chris,
Thanks for the response.
Iam using eclipselink 2.7.6 version and mapping are as below . We are using descriptor to define the mapping.

<attribute-mapping xsi:type="one-to-one-mapping">
<attribute-name>kursplanungen</attribute-name>
<reference-class>de.bund.bamf.InGe.bo.impl.KursplanungenImpl</reference-class>
<foreign-key>
<field-reference>
<source-field table="KPN_ENT" name="KPN_ID" xsi:type="column"/>
<target-field table="Kursplanungen" name="ID" xsi:type="column"/>
</field-reference>
</foreign-key>
<foreign-key-fields>
<field table="KPN_ENT" name="KPN_ID" xsi:type="column"/>
</foreign-key-fields>
<indirection xsi:type="value-holder-indirection-policy"/>
<selection-query xsi:type="read-object-query"/>
</attribute-mapping>


And it is unidirectional one-to-one mapping.

I get below error while deleting the object .

Internal Exception: java.sql.SQLException: ORA-01407: Unable to update ("KPN_ENT"."KPN_ID") to NULL

Error Code: 1407
Call: UPDATE KPN_ENT SET KPN_ID = ?, LOCKING_TIMESTAMP = ? WHERE ((ID = ?) AND (LOCKING_TIMESTAMP = ?))
bind => [null, 2024-01-22 11:42:08.853117, 200011, 2024-01-22 11:41:57.923187]
Query: UpdateObjectQuery(KPN_Ent@6a16ee0d)


But how to make eclipselink know about the null constraint ? We do not have nullable element in eclipselink_persistence_map.xsd but when i tried with @JoinColumn(nullable= false ) but it doesnot work .

I found below link where it says as bug but not sure whether it is resolved or not

https://bugs.eclipse.org/bugs/show_bug.cgi?id=341709

[Updated on: Wed, 24 January 2024 11:36]

Report message to a moderator

Re: Delete operation calling update statement to make foreign key field to null [message #1863967 is a reply to message #1863273] Fri, 08 March 2024 10:38 Go to previous messageGo to next message
Sanjana C is currently offline Sanjana CFriend
Messages: 31
Registered: December 2022
Member
Hi Chris/Team,

As you have mentioned, there is a cyclic dependency which is why may be eclipselink JPA trying to update the foreign key column to null.

I got the resolution i.e., making updatable=false to mapping resolves it.

But in my project , we are using project.xml and session.xml .If you see in project.xml(http://www.eclipse.org/eclipselink/xsds/persistence) , there is no xml element to make the updatable attribute to false.

I know that the element is there in eclipselink-orm.xml but i can use either session.xml with project.xml or orm mapping.

So is there any other way to implement this using existing configuration ?


Thanks,
Sanjana
Re: Delete operation calling update statement to make foreign key field to null [message #1864516 is a reply to message #1863967] Wed, 20 March 2024 21:03 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 54
Registered: December 2021
Member
Prior to JPA, EclipseLink/TopLink only allowed marking mappings as 'read-only', which is equivalent to marking it both with insertable and updatable=false. You should be able to do the same in the native XML descriptors, or define a session customizer to mark the mapping with the updatable=false with the java api ( I don't have the code handy to check what api that would be though).

Best Regards,
Chris
Previous Topic:How to generate Metamodel classes with maven
Next Topic:How should static weaving be done in EclipseLink recent versions like 4.0.0
Goto Forum:
  


Current Time: Sun Apr 28 18:25:38 GMT 2024

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

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

Back to the top