Cascade Remove problem [message #1061603] |
Mon, 03 June 2013 08:55 |
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02378 seconds