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 Keith Rogers <ke...@mouchelparkman.com> on 2004/04/07 11:11:01 UTC
reference descriptors not inherited in multi-table inheritence
It seems to me that if you define a reference in a base class, and then
have another class that inherits from it, then the reference-descriptor
elements are not inherited.
For example, using the example at the end of the mail, if you query and
retrieve a User, you can use a getUserStatus() method to retrieve the
correct UserStatus object.
However, if you query and retrieve a Person, you can get the correct id
of the user status (using a getUserStatusId() method), but calling
getUserStatus() will return null.
Is this the correct behaviour, or have I made a mistake in the
configuration? If this is the correct behaviour, how could I work around
it? I'm sure this could be done using the "mapping each class to a
distinct table" inheritence strategy, but this would involve modifying
an existing database, which I am reluctant to do for compatability
reasons.
Example - please assume that relevent get/set methods are implemented
public class User
{
protected int id;
protected String username;
protected String password;
protected int userStatusId;
protected UserStatus userStatus;
}
public class Person extends User
{
protected String surname;
protected String forename;
}
public class UserStatus
{
protected int id;
protected String name;
}
<class-descriptor class="User" table="users">
<field-descriptor name="id" column="user_id"
jdbc-type="INTEGER" primarykey="true" autoincrement="true"/>
<field-descriptor name="username" column="username"
jdbc-type="VARCHAR"/>
<field-descriptor name="password" column="password"
jdbc-type="VARCHAR"/>
<field-descriptor name="userStatusId" column="status"
jdbc-type="INTEGER"/>
<reference-descriptor name="userLevel"
class-ref="com.mp.hato.ojb.OJBUserLevel" auto-retrieve="true">
<foreignkey field-ref="userLevelId"/>
</reference-descriptor>
</class-descriptor>
<class-descriptor class="Person" table="people">
<field-descriptor name="id" column="id"
jdbc-type="INTEGER" primarykey="true"/>
<field-descriptor name="surname"
column="surname" jdbc-type="VARCHAR"/>
<field-descriptor name="forename"
column="forename" jdbc-type="VARCHAR"/>
<reference-descriptor name="super"
class-ref="com.mp.hato.ojb.OJBUser" auto-retrieve="true"
auto-update="true" auto-delete="true">
<foreignkey field-ref="id"/>
</reference-descriptor>
</class-descriptor>
<class-descriptor class="UserStatus" table="user_status">
<field-descriptor name="id" column="id" jdbc-type="INTEGER"
primarykey="true"/>
<field-descriptor name="name" column="name" jdbc-type="VARCHAR"/>
</class-descriptor>
The information in this e-mail is confidential and intended to be solely for the use of the addressee(s) and may contain copyright and/or legally privileged information. If you are not the addressee (or responsible for delivery of the message to the addressee) please e-mail us at Postmaster@mouchelparkman.com and delete the message from your computer; copying, distribution, use or disclosure of its contents is strictly prohibited.
As Internet communications are capable of data corruption no responsibility is accepted for changes made to this message after it was sent. For this reason it may be inappropriate to rely on advice contained in any e-mail without obtaining written confirmation of it.
In addition, no liability or responsibility is accepted for viruses and it is your responsibility to scan attachments (if any).
Please note that for business purposes, outgoing and incoming emails from and to the company may be monitored and recorded.
Mouchel Parkman UK Ltd, Registered in England at West Hall, Parvis Road, West Byfleet, Surrey UK KT14 6EZ Registered No : 1686040
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: reference descriptors not inherited in multi-table inheritence
Posted by Armin Waibel <ar...@apache.org>.
Hi Tom,
Thomas Dudziak wrote:
> I wasn't aware that reference descriptors can be inherited !
The problem is that they can't ;-)
But to make the "Mapping Classes on Multiple Joined Tables" feature full
compatible we need inheritance of references in this case or the
possibility to resolve the path to the reference.
> Is this
> somewhere in the docs ? I gotta check if this should be handled by the
> XDoclet module ...
I will add a known issue note to release-notes, because I don't think we
will be able to fix this before final 1.0.
regards,
Armin
>
> Keith, please ignore my post then ;-)
>
> Tom
>
> On Wed, 7 Apr 2004, Armin Waibel wrote:
>
>
>>Hi Keith,
>>
>>this is a known issue (sorry forget to answer your previous post). I
>>checked in a test called
>>InheritanceMultipleTableTest#testQuery_InheritedReference a few days ago.
>>I don't know a workaround for this problem. If you declare the reference
>>in the sub-class Person too you have to modify the sub-class table and
>>this will cause side-effects if you want all User with a specific status.
>>The problem is that the path "userStatus.name" could not be resolved by
>>SqlGeneratorDefaultImpl.
>>
>>regards,
>>Armin
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: reference descriptors not inherited in multi-table inheritence
Posted by Thomas Dudziak <to...@first.gmd.de>.
I wasn't aware that reference descriptors can be inherited ! Is this
somewhere in the docs ? I gotta check if this should be handled by the
XDoclet module ...
Keith, please ignore my post then ;-)
Tom
On Wed, 7 Apr 2004, Armin Waibel wrote:
> Hi Keith,
>
> this is a known issue (sorry forget to answer your previous post). I
> checked in a test called
> InheritanceMultipleTableTest#testQuery_InheritedReference a few days ago.
> I don't know a workaround for this problem. If you declare the reference
> in the sub-class Person too you have to modify the sub-class table and
> this will cause side-effects if you want all User with a specific status.
> The problem is that the path "userStatus.name" could not be resolved by
> SqlGeneratorDefaultImpl.
>
> regards,
> Armin
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: reference descriptors not inherited in multi-table inheritence
Posted by Armin Waibel <ar...@apache.org>.
Hi Keith,
this is a known issue (sorry forget to answer your previous post). I
checked in a test called
InheritanceMultipleTableTest#testQuery_InheritedReference a few days ago.
I don't know a workaround for this problem. If you declare the reference
in the sub-class Person too you have to modify the sub-class table and
this will cause side-effects if you want all User with a specific status.
The problem is that the path "userStatus.name" could not be resolved by
SqlGeneratorDefaultImpl.
regards,
Armin
Keith Rogers wrote:
> It seems to me that if you define a reference in a base class, and then
> have another class that inherits from it, then the reference-descriptor
> elements are not inherited.
>
> For example, using the example at the end of the mail, if you query and
> retrieve a User, you can use a getUserStatus() method to retrieve the
> correct UserStatus object.
> However, if you query and retrieve a Person, you can get the correct id
> of the user status (using a getUserStatusId() method), but calling
> getUserStatus() will return null.
> Is this the correct behaviour, or have I made a mistake in the
> configuration? If this is the correct behaviour, how could I work around
> it? I'm sure this could be done using the "mapping each class to a
> distinct table" inheritence strategy, but this would involve modifying
> an existing database, which I am reluctant to do for compatability
> reasons.
>
> Example - please assume that relevent get/set methods are implemented
>
> public class User
> {
> protected int id;
> protected String username;
> protected String password;
> protected int userStatusId;
> protected UserStatus userStatus;
> }
>
> public class Person extends User
> {
> protected String surname;
> protected String forename;
> }
>
> public class UserStatus
> {
> protected int id;
> protected String name;
> }
>
> <class-descriptor class="User" table="users">
> <field-descriptor name="id" column="user_id"
> jdbc-type="INTEGER" primarykey="true" autoincrement="true"/>
> <field-descriptor name="username" column="username"
> jdbc-type="VARCHAR"/>
> <field-descriptor name="password" column="password"
> jdbc-type="VARCHAR"/>
> <field-descriptor name="userStatusId" column="status"
> jdbc-type="INTEGER"/>
>
> <reference-descriptor name="userLevel"
> class-ref="com.mp.hato.ojb.OJBUserLevel" auto-retrieve="true">
> <foreignkey field-ref="userLevelId"/>
> </reference-descriptor>
> </class-descriptor>
>
> <class-descriptor class="Person" table="people">
> <field-descriptor name="id" column="id"
> jdbc-type="INTEGER" primarykey="true"/>
> <field-descriptor name="surname"
> column="surname" jdbc-type="VARCHAR"/>
> <field-descriptor name="forename"
> column="forename" jdbc-type="VARCHAR"/>
>
> <reference-descriptor name="super"
> class-ref="com.mp.hato.ojb.OJBUser" auto-retrieve="true"
> auto-update="true" auto-delete="true">
> <foreignkey field-ref="id"/>
> </reference-descriptor>
> </class-descriptor>
>
> <class-descriptor class="UserStatus" table="user_status">
> <field-descriptor name="id" column="id" jdbc-type="INTEGER"
> primarykey="true"/>
> <field-descriptor name="name" column="name" jdbc-type="VARCHAR"/>
> </class-descriptor>
>
>
> The information in this e-mail is confidential and intended to be solely for the use of the addressee(s) and may contain copyright and/or legally privileged information. If you are not the addressee (or responsible for delivery of the message to the addressee) please e-mail us at Postmaster@mouchelparkman.com and delete the message from your computer; copying, distribution, use or disclosure of its contents is strictly prohibited.
> As Internet communications are capable of data corruption no responsibility is accepted for changes made to this message after it was sent. For this reason it may be inappropriate to rely on advice contained in any e-mail without obtaining written confirmation of it.
> In addition, no liability or responsibility is accepted for viruses and it is your responsibility to scan attachments (if any).
> Please note that for business purposes, outgoing and incoming emails from and to the company may be monitored and recorded.
>
> Mouchel Parkman UK Ltd, Registered in England at West Hall, Parvis Road, West Byfleet, Surrey UK KT14 6EZ Registered No : 1686040
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: reference descriptors not inherited in multi-table inheritence
Posted by Thomas Dudziak <to...@first.gmd.de>.
On Wed, 7 Apr 2004, Keith Rogers wrote:
> It seems to me that if you define a reference in a base class, and then
> have another class that inherits from it, then the reference-descriptor
> elements are not inherited.
>
> For example, using the example at the end of the mail, if you query and
> retrieve a User, you can use a getUserStatus() method to retrieve the
> correct UserStatus object.
> However, if you query and retrieve a Person, you can get the correct id
> of the user status (using a getUserStatusId() method), but calling
> getUserStatus() will return null.
> Is this the correct behaviour, or have I made a mistake in the
> configuration? If this is the correct behaviour, how could I work around
> it? I'm sure this could be done using the "mapping each class to a
> distinct table" inheritence strategy, but this would involve modifying
> an existing database, which I am reluctant to do for compatability
> reasons.
>
> Example - please assume that relevent get/set methods are implemented
>
> public class User
> {
> protected int id;
> protected String username;
> protected String password;
> protected int userStatusId;
> protected UserStatus userStatus;
> }
>
> public class Person extends User
> {
> protected String surname;
> protected String forename;
> }
>
> public class UserStatus
> {
> protected int id;
> protected String name;
> }
>
> <class-descriptor class="User" table="users">
> <field-descriptor name="id" column="user_id"
> jdbc-type="INTEGER" primarykey="true" autoincrement="true"/>
> <field-descriptor name="username" column="username"
> jdbc-type="VARCHAR"/>
> <field-descriptor name="password" column="password"
> jdbc-type="VARCHAR"/>
> <field-descriptor name="userStatusId" column="status"
> jdbc-type="INTEGER"/>
>
> <reference-descriptor name="userLevel"
> class-ref="com.mp.hato.ojb.OJBUserLevel" auto-retrieve="true">
> <foreignkey field-ref="userLevelId"/>
> </reference-descriptor>
> </class-descriptor>
>
> <class-descriptor class="Person" table="people">
> <field-descriptor name="id" column="id"
> jdbc-type="INTEGER" primarykey="true"/>
> <field-descriptor name="surname"
> column="surname" jdbc-type="VARCHAR"/>
> <field-descriptor name="forename"
> column="forename" jdbc-type="VARCHAR"/>
>
> <reference-descriptor name="super"
> class-ref="com.mp.hato.ojb.OJBUser" auto-retrieve="true"
> auto-update="true" auto-delete="true">
> <foreignkey field-ref="id"/>
> </reference-descriptor>
> </class-descriptor>
>
> <class-descriptor class="UserStatus" table="user_status">
> <field-descriptor name="id" column="id" jdbc-type="INTEGER"
> primarykey="true"/>
> <field-descriptor name="name" column="name" jdbc-type="VARCHAR"/>
> </class-descriptor>
As far as I can see, there are two problems here:
* OJB is only aware of the inheritance hierarchy if you declare it in your
class descriptor, e.g. in your case:
<class-descriptor class="User" table="users">
<extent-class class-ref="Person"/>
...
(Note that this is the opposite direction to the Java 'extends').
* Descriptors are not inherited in OJB. If you want a subclass to have the
same fields/references/collections as its base class in terms of the
database, then you have to specify them again in the class-descriptor of
the subclass. You should also take care that the definitions of the
primary keys are equal, otherwise you might run into problems (in your
case the primary key of User is autoincrement, but the primary key of
Person is not).
This is btw. independent of whether you map the base- and subclass to the
same or to different tables.
You might want to check out the XDoclet OJB module which handles this
automatically for you.
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org