Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » ManyToOne and JoinTable(ManyToOne and JoinTable (remove cascade not desired))
icon5.gif  ManyToOne and JoinTable [message #987653] Tue, 27 November 2012 13:00 Go to next message
Sergio a is currently offline Sergio aFriend
Messages: 3
Registered: November 2012
Junior Member
Hello,

My eclipseLink version is 2.1.3, im using both @ManyToOne and @JoinTable to mapping this situation:

   @ManyToOne(fetch = FetchType.EAGER)
   @JoinTable(name = "TABLE_USER_ADDRESS", joinColumns = @JoinColumn(name = "USER_ID", referencedColumnName = "USERID"),
       inverseJoinColumns = @JoinColumn(name = "ADDR_ID", referencedColumnName = "ADDRESSID"))
   private Address address;


When remove an User, jpa try to remove the Address associated. Although the address is associated with more users (hence ManyToOne).

I am new using EclipseLink jpa Smile, am I doing something wrong? How I can state that no cascade delete? (default cascade is emtpy array, I've also tried putting cascade = {})

Thanks, regards.
Re: ManyToOne and JoinTable [message #987697 is a reply to message #987653] Tue, 27 November 2012 16:17 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

JPA will not delete the Address unless you call remove() with the Address, or have set cascade remove.

JPA will delete the row from the join table, as that row is owned by the User object.

What is your SQL log?


James : Wiki : Book : Blog : Twitter
Re: ManyToOne and JoinTable [message #987798 is a reply to message #987697] Wed, 28 November 2012 08:37 Go to previous messageGo to next message
Sergio a is currently offline Sergio aFriend
Messages: 3
Registered: November 2012
Junior Member
Hi,

Thank you very much for the quick response.

The SQL log:
[EL Fine]: 2012-11-28 09:19:30.276--ServerSession(219730313)--Connection(764103883)--Thread(Thread[DistributedCache:MetadataCache,10,Cluster])--SELECT USERID FROM USER WHERE (USERID = ?)
	bind => [administrationUser]
[EL Fine]: 2012-11-28 09:19:30.278--ServerSession(219730313)--Connection(764103883)--Thread(Thread[DistributedCache:MetadataCache,10,Cluster])--SELECT t1.USERID FROM TABLE_USER_ADDRESS t0, USER t1 WHERE ((t0.USER_ID = ?) AND (t1.USERID = t0.USER_ID))
	bind => [administrationUser]
[EL Fine]: 2012-11-28 09:19:30.283--ClientSession(1080497174)--Connection(764103883)--Thread(Thread[DistributedCache:MetadataCache,10,Cluster])--DELETE FROM TABLE_USER_ADDRESS WHERE (USER_ID = ?)
	bind => [administrationUser]
[EL Fine]: 2012-11-28 09:19:30.287--ClientSession(1080497174)--Connection(764103883)--Thread(Thread[DistributedCache:MetadataCache,10,Cluster])--DELETE FROM USER WHERE (USER_USERGROUP = ?)
	bind => [administrationUser]
[EL Fine]: 2012-11-28 09:19:30.308--ServerSession(219730313)--Connection(764103883)--Thread(Thread[DistributedCache:MetadataCache,10,Cluster])--SELECT ADDRID FROM ADDRESS WHERE (ADDRID = ?)
	bind => [addrIDUserAdministration]
[EL Fine]: 2012-11-28 09:19:30.31--ClientSession(909751202)--Connection(764103883)--Thread(Thread[DistributedCache:MetadataCache,10,Cluster])--DELETE FROM ADDRESS WHERE (ADDRID = ?)
	bind => [addrIDUserAdministration]
[EL Fine]: 2012-11-28 09:19:30.391--ClientSession(909751202)--Thread(Thread[DistributedCache:MetadataCache,10,Cluster])--SELECT 1 FROM DUAL
[EL Warning]: 2012-11-28 09:19:30.411--UnitOfWork(1335606662)--Thread(Thread[DistributedCache:MetadataCache,10,Cluster])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.1.v20111018-r10243): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-02292: integrity constraint (USERADDR_TABLE_USER_ADDRESSSRID) violated - child record found

Error Code: 2292
Call: DELETE FROM ADDRESS WHERE (ADDRID = ?)
	bind => [addrIDUserAdministration]
Query: DeleteObjectQuery(Address{key=AddressKey{key=addrIDUserAdministration}})
Re: ManyToOne and JoinTable [message #989099 is a reply to message #987798] Tue, 04 December 2012 15:35 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Seems to be a bug. Please log the bug and vote for it.

(the issues is in ObjectReferenceMapping.preDelete(), the isForeignKeyRelationship() check is wrong).


James : Wiki : Book : Blog : Twitter
Re: ManyToOne and JoinTable [message #989200 is a reply to message #989099] Wed, 05 December 2012 08:34 Go to previous message
Sergio a is currently offline Sergio aFriend
Messages: 3
Registered: November 2012
Junior Member
Hi,

Bug created:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=395739

Thanks.
Regards.
Previous Topic: Issue with inheritance and join fetching
Next Topic:@CascadeOnDelete
Goto Forum:
  


Current Time: Thu Apr 25 06:41:14 GMT 2024

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

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

Back to the top