You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by MB...@gmx.de on 2004/10/05 13:00:07 UTC
Problem mapping an inheritance hierarchy to joined tables
Hi,
I have some problems mapping an inheritance structure to joined tables.
I´m using the PersistenceBroker API.
Everything worked fine, util I started to use a composed primary key to keep
the history.
The base class primary key contains a field called customerID and some
fields for keeping the history (date of change, sequencenumber etc.).
The derived classes contain the same primary key (customerID, date of
change, sequencenumber...) and a field called ID with anonymous access for
an unique primary key value (for the customerID) in the derived tables.
First with OJB 1.0rc7, I got an unique value for the entries in the derived
class´ tables,
but the other field in base class´ table were null (I know that this bug is
already fixed (OJB275 I think)).
Now with OJB 1.0.1 (no mapping or code changes since the test with rc7) the
fields of base class table get filled well, but I don´t get an unique value
in the derived classes tables customerID, for example:
View of the db tables:
#################################RC7######################################
Person (Base class´
table):
-----------------------------------------------------------------------------
| CustomerID (PK) | Date of change (PK) | Sequencenumber (PK)| Firstcontact
------------------|---------------------|--------------------|---------------
| 11 | null | null | 19990908
Company (the corresponding derived class´ table):
--------------------------------------------------------------------------|
| ID | CustomerID (PK) | Date of change (PK) | Sequencenumber (PK)| Name
-----|-----------------|---------------------|--------------------|-------|
| 11 | 12 | 20041001 | 1 | Test
^ ^
The important point
In this case I were able to load the object for the base class
and got the right derived class typed object (CompanyBO).
(of course I used "2" as value for the
customerID).
##################################################################################
###################################1.0.1##########################################
---------------------------------------------------------------------------
CustomerID (PK) | Date of change (PK) | Sequencenumber (PK)| Firstcontact |
----------------|---------------------|--------------------|---------------
11 | 20041001 | 1 | 19990908
The corresponding derived class´ table (company):
--------------------------------------------------------------------------
| ID | CustomerID (PK) | Date of change (PK) | Sequencenumber (PK)| Name
-----|-----------------|---------------------|--------------------|-------
11 | 11 | 20041001 | 1 | Test
^ ^
The important point
In this case when I am trying to load the object for the base class,
I only get a base class typed object
(PersonBO).
###################################################################################
I tried some OJB versions (and built some by myself from the cvs repository)
and came to the conclusion that in every version where the bug OJB275 is
fixed this bug (if it is one) occurs.
Do I have to set an extra attribute or is this a bug (or am I doing
something wrong which worked before 1.0.1) ?
Does anyone know a solution with OJB 1.0.1 to keep the "polymorph" read
access ?
Thanks for your time.
Regards,
Michael
--
+++ GMX DSL Premiumtarife 3 Monate gratis* + WLAN-Router 0,- EUR* +++
Clevere DSL-Nutzer wechseln jetzt zu GMX: http://www.gmx.net/de/go/dsl
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Problem mapping an inheritance hierarchy to joined tables
Posted by Armin Waibel <ar...@apache.org>.
Hi Michael,
if you insert an Company object OJB internally create an Person object
and pass all field values from Company to this internal Person object.
So the result for 1.1 seems as expected, if the Company object PK field
has value 11 (primarykey attribute on OJB level not DB level), the
Person object will get 11 and the FK field in Company has 11 too.
If you use an compound PK the FK has to reflect the compound PK (e.g. if
key is (Integer,String) you need two "foreignkey field-ref" entry in
reference-descriptor).
Please have a look at test suite class
...broker.InheritanceMultipleTableTest.java
this test use inheritance objects, mapping could be found in
repository_junit.xml
regards,
Armin
MBaetgen@gmx.de wrote:
> Hi,
> I have some problems mapping an inheritance structure to joined tables.
> I´m using the PersistenceBroker API.
> Everything worked fine, util I started to use a composed primary key to keep
> the history.
> The base class primary key contains a field called customerID and some
> fields for keeping the history (date of change, sequencenumber etc.).
> The derived classes contain the same primary key (customerID, date of
> change, sequencenumber...) and a field called ID with anonymous access for
> an unique primary key value (for the customerID) in the derived tables.
>
> First with OJB 1.0rc7, I got an unique value for the entries in the derived
> class´ tables,
> but the other field in base class´ table were null (I know that this bug is
> already fixed (OJB275 I think)).
> Now with OJB 1.0.1 (no mapping or code changes since the test with rc7) the
> fields of base class table get filled well, but I don´t get an unique value
> in the derived classes tables customerID, for example:
>
> View of the db tables:
> #################################RC7######################################
> Person (Base class´
> table):
> -----------------------------------------------------------------------------
> | CustomerID (PK) | Date of change (PK) | Sequencenumber (PK)| Firstcontact
>
> ------------------|---------------------|--------------------|---------------
> | 11 | null | null | 19990908
>
>
> Company (the corresponding derived class´ table):
> --------------------------------------------------------------------------|
> | ID | CustomerID (PK) | Date of change (PK) | Sequencenumber (PK)| Name
>
> -----|-----------------|---------------------|--------------------|-------|
> | 11 | 12 | 20041001 | 1 | Test
>
> ^ ^
> The important point
>
> In this case I were able to load the object for the base class
> and got the right derived class typed object (CompanyBO).
> (of course I used "2" as value for the
> customerID).
> ##################################################################################
>
>
>
>
> ###################################1.0.1##########################################
> ---------------------------------------------------------------------------
> CustomerID (PK) | Date of change (PK) | Sequencenumber (PK)| Firstcontact |
> ----------------|---------------------|--------------------|---------------
> 11 | 20041001 | 1 | 19990908
>
> The corresponding derived class´ table (company):
> --------------------------------------------------------------------------
> | ID | CustomerID (PK) | Date of change (PK) | Sequencenumber (PK)| Name
>
> -----|-----------------|---------------------|--------------------|-------
> 11 | 11 | 20041001 | 1 | Test
> ^ ^
> The important point
>
> In this case when I am trying to load the object for the base class,
> I only get a base class typed object
> (PersonBO).
> ###################################################################################
>
> I tried some OJB versions (and built some by myself from the cvs repository)
> and came to the conclusion that in every version where the bug OJB275 is
> fixed this bug (if it is one) occurs.
>
> Do I have to set an extra attribute or is this a bug (or am I doing
> something wrong which worked before 1.0.1) ?
> Does anyone know a solution with OJB 1.0.1 to keep the "polymorph" read
> access ?
>
> Thanks for your time.
>
> Regards,
> Michael
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org