Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Set join column to null after removing the related row?(How to set a join column to null if the related row was removed)
icon5.gif  Set join column to null after removing the related row? [message #524275] Wed, 31 March 2010 11:46 Go to next message
Christian is currently offline ChristianFriend
Messages: 8
Registered: March 2010
Junior Member
Hi,

I have a one-to-one relationship and want to set the join column of this relation to null if the related row was removed. At the moment I just found ways to cascade which removes the row in the child table. I need a way to say it in SQL like "ON DELETE SET NULL".
All what I try removes the child row(cascade, orphan-removal, private-owned, ...). Any suggestions what I have to do? Thanks in advance!

regards
Christian
Re: Set join column to null after removing the related row? [message #524634 is a reply to message #524275] Thu, 01 April 2010 16:13 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello Christian,

JPA does not maintain relationships for you, so if the application removes an entity, the application will need to clean up/null out references to that entity itself. You can use the "ON DELETE SET NULL" in the database to null out FKs, but this will leave objects in the cache inconsistent with what is in the database - objects referencing the removed entity will still reference it in the cache. This can be overcome if you manually refresh the objects with these references, but this comes at the expense of a database hit anyway.

If the problem is that the code doing the remove cannot know of the objects that are left referencing it, the application could use a the pre-update/remove/write event methods to manage referencing relationships. These methods might allow the modified entity to manage relationships other Entities might have to it.

Best Regards,
Chris
Re: Set join column to null after removing the related row? [message #524742 is a reply to message #524634] Fri, 02 April 2010 07:52 Go to previous message
Christian is currently offline ChristianFriend
Messages: 8
Registered: March 2010
Junior Member
Hello Chris,

thanks for you reply!
That means I needn't to create any relation (one-to-one, ...) but I have to set to "null", with the event methods, manually, haven't?

What I want to do: I'll link an "Account" with the corresponding "Session". Account has a Column "FK_SESSION_ID", this column I need to set to null if the session expire or becomes invalid otherwise. Should I realize it on another way or is my intention the right way? I just want that one Account can only have one or none Session.

best regards
Christian
Previous Topic:Unexplained Update Statements affecting Concurrency
Next Topic:Record persist order
Goto Forum:
  


Current Time: Fri Apr 26 23:24:01 GMT 2024

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

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

Back to the top