| Problems with cascade delete doing update instead [message #835105] |
Mon, 02 April 2012 16:10  |
Dave Brosius Messages: 11 Registered: July 2009 |
Junior Member |
|
|
I have a one to many relationship between a parent (workflow) and children (stage). In the database i have a delete constraint such that deletes on workflow delete stage. This works fine from sqlplus.
class Workflow {
@Override
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "workflow", targetEntity = Stage.class)
@JoinColumn(name = "WORKFLOW_ID")
public Set<Stage> getStages() {
return m_stages;
}
}
class Stage {
@Override
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false, targetEntity = Workflow.class)
@JoinColumn(name = "WORKFLOW_ID", nullable = false)
public Workflow getWorkflow() {
return m_workflow;
}
}
when i load the workflow by name inside a @Transactional(propagation = Propagation.REQUIRED) method and then em.remove(workflow) that object,
I get exceptions, such as
Error Code: 1407
Call: UPDATE STAGES SET WORKFLOW_ID = ?, FAILURE_STAGE_ID = ?, SUCCESS_STAGE_ID = ? WHERE (STAGE_ID = ?)
bind => [4 parameters bound]
Caused by: java.sql.SQLException: ORA-01407: cannot update ("AVONDALE"."STAGES"."WORKFLOW_ID") to NULL
because I have defined the stages.workflow_id column to be not nullable.
Why is eclipselink trying to update the stages table with null workflow ids, rather than just deleting the stage row itself? How do i fix that?
|
|
|
|
| Re: Problems with cascade delete doing update instead [message #836551 is a reply to message #836526] |
Wed, 04 April 2012 12:10   |
Dave Brosius Messages: 11 Registered: July 2009 |
Junior Member |
|
|
>> Are you nulling out the Stage->Workflow relationship and if so, why?
no i am not
ok i added @CascadeOnDelete as
@Override
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "workflow", targetEntity = Stage.class)
@JoinColumn(name = "WORKFLOW_ID")
@CascadeOnDelete
public Set<Stage> getStages() {
return m_stages;
}
this does nothing different.
[Updated on: Wed, 04 April 2012 12:18] Report message to a moderator
|
|
|
|
|
| Re: Problems with cascade delete doing update instead [message #836668 is a reply to message #836653] |
Wed, 04 April 2012 15:20  |
Chris Delahunt Messages: 863 Registered: July 2009 |
Senior Member |
|
|
I would suggest you set EclipseLink logging to Finest and enable parameter logging as described here:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging
to see what is going on so you can narrow down the object that is responsible for the exception and follow how it is being corrupted. Please verify that you do not have any preremove events that might be attempting to clean up relationships. You might also want to call em.flush() before the remove call to verify that there are no changes to the relationship that would account for the null that you are unaware of. Do you have any other mappings that touch on the WORKFLOW_ID field in Stages?
Best Regards,
Chris
|
|
|
Powered by
FUDForum. Page generated in 0.01928 seconds