Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » CascadeType=ALL does not result in ON DELETE CASCADE?
CascadeType=ALL does not result in ON DELETE CASCADE? [message #389729] Wed, 24 June 2009 13:25 Go to next message
Frank Sauer is currently offline Frank Sauer
Messages: 14
Registered: July 2009
Junior Member
I have a situation where CascadeType=ALL and even @PrivateOwned does not
result in child object being deleted. IN fact deletion results in FK
constraint violations... Here are the JPA annotations:

@OneToMany(cascade = CascadeType.ALL , fetch = FetchType.EAGER)
@JoinTable(name = "PLimitSlice_PossibleValue", joinColumns = {
@JoinColumn(name = "PLIMITSLICE_ID", referencedColumnName = "ID") },
inverseJoinColumns = @JoinColumn(name = "POSSIBLEVALUE_ID",
referencedColumnName = "ID"))
@PrivateOwned
private List<PossibleValue> possibleLimitValues = new
ArrayList<PossibleValue>();



and the resulting DB2MainFrame DDL below- which prevents me from deleting
anything... This occurs with most if not all of our relations. What do I
have to do to make either the FK constraint go away or get cascading
deletes going?

Thanks,

Frank


-- Version: V5R4M0 060210
-- Generated on: 06/24/09 08:17:50
-- Relational Database: D100585M
-- Standards Option: DB2 UDB iSeries

CREATE TABLE PDE_REPO2.PLIMITSLICE_POSSIBLEVALUE (
PLIMITSLICE_ID FOR COLUMN PLIMI00001 VARCHAR(255) CCSID 37 NOT NULL ,
POSSIBLEVALUE_ID FOR COLUMN POSSI00001 VARCHAR(255) CCSID 37 NOT NULL ,
CONSTRAINT PDE_REPO2.Q_PDE_REPO2_PLIMI00001_PLIMI00001_00001 PRIMARY KEY(
PLIMITSLICE_ID , POSSIBLEVALUE_ID ) )
;

ALTER TABLE PDE_REPO2.PLIMITSLICE_POSSIBLEVALUE
ADD CONSTRAINT PDE_REPO2.FK_PLIMITSLICE_POSSIBLEVALUE_PLIMITSLICE_ID
FOREIGN KEY( PLIMITSLICE_ID )
REFERENCES PDE_REPO2.PLIMITSLICE ( ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION ;

ALTER TABLE PDE_REPO2.PLIMITSLICE_POSSIBLEVALUE
ADD CONSTRAINT PDE_REPO2.FK_PLIMITSLICE_POSSIBLEVALUE_POSSIBLEVALUE_ID
FOREIGN KEY( POSSIBLEVALUE_ID )
REFERENCES PDE_REPO2.POSSIBLEVALUE ( ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION ;
Re: CascadeType=ALL does not result in ON DELETE CASCADE? [message #389732 is a reply to message #389729] Wed, 24 June 2009 14:56 Go to previous messageGo to next message
Doug Clarke is currently offline Doug Clarke
Messages: 155
Registered: July 2009
Senior Member
Frank,

Cascade.REMOVE or Cascade.ALL should cause the child object to be removed
when the parent is removed.

@PrivateOwned will cause the child to be removed when the transaction
where a child was de-referenced.

Can you show a code example for how the child is being effected in the
transaction where you expect it to be deleted?

Doug
Re: CascadeType=ALL does not result in ON DELETE CASCADE? [message #389733 is a reply to message #389732] Wed, 24 June 2009 19:00 Go to previous messageGo to next message
Frank Sauer is currently offline Frank Sauer
Messages: 14
Registered: July 2009
Junior Member
All my code tries to do is delete an instance of the parent class but as a
result the Fk constraint on the JoinTable is being violated..... We
switched from OpenJPA to Eclipselink and OpenJPA never added FK
constraints to the join tables, but eclipselink does...... What surprises
me though is that that eclipselink is violating constraints it
generated... It should remove the row in the join table first, and then
the endpoints, and everything would be good...

I got around this for now by removing the JoinTable annotation and using a
@OneToMany with a mappedBy attribute

Thanks,

Frank
Re: CascadeType=ALL does not result in ON DELETE CASCADE? [message #389734 is a reply to message #389733] Wed, 24 June 2009 23:10 Go to previous messageGo to next message
Doug Clarke is currently offline Doug Clarke
Messages: 155
Registered: July 2009
Senior Member
Frank,

Sorry, I missed the JoinTable. In general I use OneToMany mappings with
the mappedBy to an inverse ManyToOne and thus no JoinTable. This
definitely works having the child deleted first prior to deleting the
parent.

I don't have an example handy right now to verify the issue but it sounds
like you need to file a bug.

Doug
Re: CascadeType=ALL does not result in ON DELETE CASCADE? [message #389740 is a reply to message #389733] Thu, 25 June 2009 13:55 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I believe this issue was fixed in the EclipseLink 2.0 stream, but has not
yet been backported to the 1.1 stream. You can try upgrading to the
latest 2.0 milestone build.

The issue is that because there is no direct constraint between the parent
and child, the EclipseLink deletion order can attempt to delete the child
object first, instead of the parent.

To workaround the issue you could,
- Use the addConstraintDependecy() API in ClassDescriptor to influence the
delete order to delete the parent object first.
- Mark the relationship as @PrivateOwned, but not as CascadeType.ALL
(don't cascade remove).
- Remove the constraint from your table, or add a cascade delete to the
constraint.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Previous Topic:TableDefinition: calls Helper.truncate with a negative size
Next Topic:remove not removing
Goto Forum:
  


Current Time: Wed Sep 17 05:51:25 GMT 2014

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

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