Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Mapping of Collection of Base class objects
Mapping of Collection of Base class objects [message #493393] Sun, 25 October 2009 18:21 Go to next message
Gopal  is currently offline Gopal Friend
Messages: 4
Registered: October 2009
Junior Member
Hi,
I have say following class structure

Class B1 and B2 inherit from Class B

And Class A has a one-to-many collection of Class B objects which could be of type B1 or B2.

I am not able to figure out how I would map these. I would like to have table-per-class inheritance strategy for Class B hierarchy if that matters.

I appreciate any help on the subject.

Thanks,
gopal
Re: Mapping of Collection of Base class objects [message #493487 is a reply to message #493393] Mon, 26 October 2009 14:00 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Have you tried just mapping the OneToMany in A to B? What error are you getting?

You may be better off using single_table or joined inheritance.


James : Wiki : Book : Blog : Twitter
Re: Mapping of Collection of Base class objects [message #493565 is a reply to message #493487] Mon, 26 October 2009 22:57 Go to previous messageGo to next message
Gopal  is currently offline Gopal Friend
Messages: 4
Registered: October 2009
Junior Member
Thanks James for the reply and Sorry, it took a while for me to configure and test this scenario.

I am getting foreign key violation exception.

It created following schema

TableA(id, ...)

TableB(id,...)

TableB1(id,...)

TableB2(id,...)

TableAB(A_id, attr_id)
Constraint1) A_id Foreign Key to id in TableA
Constraint2) attr_id is foreign key to id in TableB

When I insert an item in B1 or B2, it violates constraint2 as there is no entry in table B with that id.

Based on the problem it may work if I use JOIN table or SINGLE_TABLE inheritance strategy as you suggested, but I have requirement to use TABLE_PER_CLASS.

Any other ideas?

Re: Mapping of Collection of Base class objects [message #494173 is a reply to message #493393] Thu, 29 October 2009 13:18 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You cannot define foreign key constraints with TABLE_PER_CLASS relationships, as there is no common table to define the constraint to. That is one of the reasons why SINGLE_TABLE or JOINED is normally recommended.


James : Wiki : Book : Blog : Twitter
Previous Topic:provide mappings that are not on the classpath
Next Topic:JAPA search query on DB
Goto Forum:
  


Current Time: Tue Apr 16 06:16:01 GMT 2024

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

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

Back to the top