Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » @CascadeOnDelete
@CascadeOnDelete [message #911373] Tue, 11 September 2012 09:18 Go to next message
Eclipse UserFriend
I have a strange problem with @CascadeOnDelete annotation. For instance

@Entity
public class Employee {
	@Id
	private long id;
	private String firstName;
	private String lastName;
	@OneToMany(mappedBy = "parent", orphanRemoval = true, cascade = { CascadeType.ALL })
	@CascadeOnDelete
	private List<Employee> children;
	@ManyToOne
	private Employee parent;
}


eclipselink generates the following DDL:

CREATE TABLE EMPLOYEE (ID BIGINT NOT NULL, FIRSTNAME VARCHAR(255), LASTNAME VARCHAR(255), PARENT_ID BIGINT, PRIMARY KEY (ID))
ALTER TABLE EMPLOYEE ADD CONSTRAINT FK_EMPLOYEE_PARENT_ID FOREIGN KEY (PARENT_ID) REFERENCES EMPLOYEE (ID)

Note, that ON DELETE CASCADE is not generated, therefore it works not as expected.

Any ideas?

[Updated on: Tue, 11 September 2012 09:19] by Moderator

Re: @CascadeOnDelete [message #911510 is a reply to message #911373] Tue, 11 September 2012 14:57 Go to previous messageGo to next message
Eclipse UserFriend
What database platform are you using? The only one I know for sure that disables the On Delete Cascade is the SybasePlatform.

Regards,
Chris
Re: @CascadeOnDelete [message #911711 is a reply to message #911510] Wed, 12 September 2012 03:14 Go to previous messageGo to next message
Eclipse UserFriend
[EL Fine]: connection: 2012-09-12 11:13:21.596--Thread(Thread[main,6,main])--Detected database platform: org.eclipse.persistence.platform.database.MySQLPlatform


It seems to be the MySQLPlatform
Re: @CascadeOnDelete [message #911814 is a reply to message #911711] Wed, 12 September 2012 07:28 Go to previous messageGo to next message
Eclipse UserFriend
Try adding the @CascadeOnDelete to the @ManyToOne, not the @OneToMany.
Re: @CascadeOnDelete [message #911819 is a reply to message #911814] Wed, 12 September 2012 07:35 Go to previous messageGo to next message
Eclipse UserFriend
the same result
Re: @CascadeOnDelete [message #916047 is a reply to message #911819] Tue, 18 September 2012 09:02 Go to previous messageGo to next message
Eclipse UserFriend
Ensure you are recompiling and redeploying your code correctly. Ensure you are using the correct EclipseLink version.
Ensure you are using EclipseLink to generate your DDL, not your own scripts.
Re: @CascadeOnDelete [message #916052 is a reply to message #916047] Tue, 18 September 2012 09:08 Go to previous messageGo to next message
Eclipse UserFriend
is there any way to check that ddl files are generated by eclipselink, say, another eclipselink-specific annotation or whatever?
Re: @CascadeOnDelete [message #916091 is a reply to message #916052] Tue, 18 September 2012 10:12 Go to previous messageGo to next message
Eclipse UserFriend
If you set logging to fine or finest, is the DDL being logged from EclipseLink?
Re: @CascadeOnDelete [message #917679 is a reply to message #911373] Thu, 20 September 2012 06:17 Go to previous messageGo to next message
Eclipse UserFriend
[EL Finest]: query: 2012-09-20 14:13:23.371--ServerSession(19334979)--Thread(Thread[main,6,main])--Execute query DataModifyQuery(sql="CREATE TABLE EMPLOYEE (ID BIGINT NOT NULL, FIRSTNAME VARCHAR(255), LASTNAME VARCHAR(255), PARENT_ID BIGINT, PRIMARY KEY (ID))")
[EL Finest]: connection: 2012-09-20 14:13:23.371--ServerSession(19334979)--Connection(24804412)--Thread(Thread[main,6,main])--Connection acquired from connection pool [default].
[EL Fine]: sql: 2012-09-20 14:13:23.371--ServerSession(19334979)--Connection(24804412)--Thread(Thread[main,6,main])--CREATE TABLE EMPLOYEE (ID BIGINT NOT NULL, FIRSTNAME VARCHAR(255), LASTNAME VARCHAR(255), PARENT_ID BIGINT, PRIMARY KEY (ID))
[EL Fine]: sql: 2012-09-20 14:13:23.371--ServerSession(19334979)--Thread(Thread[main,6,main])--SELECT 1
...
[EL Finest]: query: 2012-09-20 14:13:24.48--ServerSession(19334979)--Thread(Thread[main,6,main])--Execute query DataModifyQuery(sql="ALTER TABLE EMPLOYEE ADD CONSTRAINT FK_EMPLOYEE_PARENT_ID FOREIGN KEY (PARENT_ID) REFERENCES EMPLOYEE (ID)")
[EL Finest]: connection: 2012-09-20 14:13:24.48--ServerSession(19334979)--Connection(24804412)--Thread(Thread[main,6,main])--Connection acquired from connection pool [default].
[EL Fine]: sql: 2012-09-20 14:13:24.48--ServerSession(19334979)--Connection(24804412)--Thread(Thread[main,6,main])--ALTER TABLE EMPLOYEE ADD CONSTRAINT FK_EMPLOYEE_PARENT_ID FOREIGN KEY (PARENT_ID) REFERENCES EMPLOYEE (ID)
[EL Finest]: connection: 2012-09-20 14:13:24.652--ServerSession(19334979)--Connection(24804412)--Thread(Thread[main,6,main])--Connection released to connection pool [default].


ON DELETE CASCADE is missed
Re: @CascadeOnDelete [message #923021 is a reply to message #917679] Tue, 25 September 2012 10:43 Go to previous messageGo to next message
Eclipse UserFriend
What version of EclipseLink are you using?
Re: @CascadeOnDelete [message #923780 is a reply to message #923021] Wed, 26 September 2012 03:29 Go to previous messageGo to next message
Eclipse UserFriend
eclipselink 2.4.0 - juno
Re: @CascadeOnDelete [message #930646 is a reply to message #923780] Tue, 02 October 2012 10:08 Go to previous messageGo to next message
Eclipse UserFriend
I cannot recreate this. If you can isolate a test case, please log a bug.
Re: @CascadeOnDelete [message #989559 is a reply to message #911373] Thu, 06 December 2012 12:53 Go to previous message
Eclipse UserFriend
Hi Oleg Danilov,

Have you figured that out already? I'm having the exact same problem.
Previous Topic:ManyToOne and JoinTable
Next Topic:Loging SQL to a file
Goto Forum:
  


Current Time: Wed Jul 23 07:32:12 EDT 2025

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

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

Back to the top