Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Looking for hints to map inheritance relationships

Hi Phillip,

  Can you please post the following:

- examples of how the category fields are mapped in both Product and Automobile
- a code snippet the shows what you are doing
- logging of the SQL produced and the full exception trace (for logging, use persistence unit property eclipselink.logging.level=FINEST)

-Tom

Phillip Ross wrote:
Hi all, I'm having a problem with mapping inheritance and not sure if
things are acting correctly or not.  Was hoping for some hints.

The scenario I'm working with is that I have two related entity
superclasses mapped with an inheritance strategy or JOINED, and there
is a ManyToOne relationship between the two.  The subclass entities
subclass the superclasses and override the relationship (or at least
this is what is intended).  I had first assumed that when the tables
were created, a field would be created in both the parents table and
child table... but it appears that it was only created in the parent
table.  I figured that this was OK since there would be records in the
parent tables that would map related subclass instances, but when I
attempt to persist the subclass with the ManyToOne member attribute...
an exception is thrown caused by a not-null constraint violation
corresponding to the parent table's FK field.  As an experiment, I
changed the child class to populate the related property field in both
the superclass and itself, but I'm assuming this won't really work out
in the future as fetching the correct records may not work either.

To put this in more concrete terms... say I have Product and
ProductCategory as superclasses.  Product has a property called
category which holds a ProductCategory instance.  Automobile
subclasses Product and AutomobileCategory subclasses ProductCategory.
The Automobile class defined a property named category and is defined
to be AutomobileCategory.  Since persisting an Automobile and an
AutomobileCategory would create records in all four tables... shouldnt
eclipselink know that the category field in the Product table relating
to ProductCategory be used to map the Automobile instances to the
AutomobileCategory instances?

I'm hoping someone knoww if I'm trying to map a scenario that's not
supported or if there is a trick to doing this?  Perhaps an
eclipselink specific trick that goes beyond the JPA spec?  If it is
supported and sounds like a bug... I have a test case to submit :)

Thanks!
- Phillip
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top