Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Cascade Remove problem(I have a problem with cascade Remove in Eclipselink)
Cascade Remove problem [message #1061603] Mon, 03 June 2013 08:55 Go to next message
mohamed ibrahim mohamed is currently offline mohamed ibrahim mohamedFriend
Messages: 6
Registered: April 2013
Junior Member
Dear Friends ,

The problem is as follows :

I am building something like content management system , Where i want to track which pages viewed by which users.

For this , i have class Called ActorEO which represent any employee and another class called PageEO which represents any viewable page and a HistoryLogEO which represents which pages viewed by which users . the mapping as follows

//Employee class

public class ActorEO extends EntityEO


   protected List<HistoryLog> viewHistory;


public class PageEO extends ContentEO

    //There are some fields related to pageEO in here 
   //There is no relationship with HistoryLog anyway

   //Sometimes i try to add this but it cascades the delete operation to actorEO
    //And deletes actorEO (Which i don't want to delete the actorEO)
protected List<HistoryLog> viewedHistory;


//History Log Class
public class HistoryLog extends EntityEO
    protected ActorEO performer;

     protected PageEO visitedPage;

The problem is , If i want to delete a page without putting "ViewedHistory" mapping in the pageEO , it gives me a violation of foreign keys in table History logs itself because it has a fk to the pages table .

if i tried to put ViewedHistory mapping in the pageEO , and i try to remove a page , it removes the logs and it removes the ActorEO as well which in this case is the employee , i don't want this cascade to remove the Employee.

What i want is to remove the page and any record inside the History Logs table .

How can i accomplish that in JPA Annotation or if there is any good solution for that i will really appreciate it

Thanks in advance.

[Updated on: Mon, 03 June 2013 08:55]

Report message to a moderator

Re: Cascade Remove problem [message #1061672 is a reply to message #1061603] Mon, 03 June 2013 12:49 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1296
Registered: July 2009
Senior Member

The mapping:
protected List<HistoryLog> viewedHistory;
Doesn't make sense to me as it implies that a PageEO is a HistoryLog. If PageEO extends HistoryLog, what inheritance strategy are you using and now is it mapped?

Deleting a pageEO should cause an exception unless you first clean up any references to it - specifically by nulling out any HistoryLog instances with visitedPage that reference the PageEO instance you want to delete. JPA does not maintain your bidirectional references for you.

There are no annotations on the mappings you've shown that would cause HistoryLog to be deleted when PageEO is removed; check that you are not using an ORM.xml or customizer to override settings, or that you do not have annotations elsewhere such as on the properties that might mark the relationship to be cascade remove, privately owned or use orphan removal.

Previous Topic:Object: is not a known entity type.
Next Topic:When a merge does not update?
Goto Forum:

Current Time: Sat May 26 02:35:44 GMT 2018

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

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

Back to the top