Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » @CascadeOnDelete
@CascadeOnDelete [message #911373] Tue, 11 September 2012 13:18 Go to next message
Oleg Danilov is currently offline Oleg DanilovFriend
Messages: 21
Registered: July 2012
Junior Member
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 13:19]

Report message to a moderator

Re: @CascadeOnDelete [message #911510 is a reply to message #911373] Tue, 11 September 2012 18:57 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
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 07:14 Go to previous messageGo to next message
Oleg Danilov is currently offline Oleg DanilovFriend
Messages: 21
Registered: July 2012
Junior Member
[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 11:28 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Try adding the @CascadeOnDelete to the @ManyToOne, not the @OneToMany.

James : Wiki : Book : Blog : Twitter
Re: @CascadeOnDelete [message #911819 is a reply to message #911814] Wed, 12 September 2012 11:35 Go to previous messageGo to next message
Oleg Danilov is currently offline Oleg DanilovFriend
Messages: 21
Registered: July 2012
Junior Member
the same result
Re: @CascadeOnDelete [message #916047 is a reply to message #911819] Tue, 18 September 2012 13:02 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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.


James : Wiki : Book : Blog : Twitter
Re: @CascadeOnDelete [message #916052 is a reply to message #916047] Tue, 18 September 2012 13:08 Go to previous messageGo to next message
Oleg Danilov is currently offline Oleg DanilovFriend
Messages: 21
Registered: July 2012
Junior Member
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 14:12 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

If you set logging to fine or finest, is the DDL being logged from EclipseLink?


James : Wiki : Book : Blog : Twitter
Re: @CascadeOnDelete [message #917679 is a reply to message #911373] Thu, 20 September 2012 10:17 Go to previous messageGo to next message
Oleg Danilov is currently offline Oleg DanilovFriend
Messages: 21
Registered: July 2012
Junior Member
[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 14:43 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

What version of EclipseLink are you using?


James : Wiki : Book : Blog : Twitter
Re: @CascadeOnDelete [message #923780 is a reply to message #923021] Wed, 26 September 2012 07:29 Go to previous messageGo to next message
Oleg Danilov is currently offline Oleg DanilovFriend
Messages: 21
Registered: July 2012
Junior Member
eclipselink 2.4.0 - juno
Re: @CascadeOnDelete [message #930646 is a reply to message #923780] Tue, 02 October 2012 14:08 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I cannot recreate this. If you can isolate a test case, please log a bug.

James : Wiki : Book : Blog : Twitter
Re: @CascadeOnDelete [message #989559 is a reply to message #911373] Thu, 06 December 2012 17:53 Go to previous message
Carlos Morais is currently offline Carlos MoraisFriend
Messages: 1
Registered: December 2012
Junior Member
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: Thu Apr 18 16:59:52 GMT 2024

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

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

Back to the top