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 mohamed
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

@Table(name="TBL_ACTOR")
@Entity
public class ActorEO extends EntityEO
{

  ............

   @OneToMany(cascade=CascadeType.ALL,mappedBy="performer",orphanRemoval=true,TargetEntity=HistoryLog.class) 
   protected List<HistoryLog> viewHistory;
}


//PageEO

@Table(name="TBL_PAGE")
@Entity
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)
    @OneToMany(cascade={Detach,refresh,merge},mappedBy="visitedPage",TargetEntity=PageEO.class)
protected List<HistoryLog> viewedHistory;


}



//History Log Class
@Table(name="TBL_HistoryLog")
@Entity
public class HistoryLog extends EntityEO
{
    
    @ManyToOne(cascade={Detach,refresh,merge},targetEntity=ActorEO.class)
@JoinColumn(name="PERFORMERID")
    protected ActorEO performer;


    @ManyToOne(cascade={Detach,refresh,merge},TargetEntity=PageEO.class)
     @JoinColumn(name="PageID",nullable=true)
     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 Delahunt
Messages: 1026
Registered: July 2009
Senior Member
Hello,

The mapping:
@OneToMany(cascade={Detach,refresh,merge},mappedBy="visitedPage",TargetEntity=PageEO.class)
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: Wed Oct 01 10:19:56 GMT 2014

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

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