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 Nouguier Olivier <ol...@wanadoo.fr> on 2004/06/24 16:16:31 UTC

ojb, xdoclet and inheritance

Hi all,
 We're using ojb in a big project, with many many inheritance relations.
We choose the One Table per object strategie.

So:

 class A {
  int id
  int fieldA
}

 Class B extends A {
   int fieldB
} 

Using xdoclet for generating mapping file brings us to put an
@ojb.reference name="id" in Class B header, but for this to work we need
to declare id as anonymous field of B ( @ojb.field also in header ).

As consequence id of A is never filled with db data ( anonymous ). If we
change access="readonly" in mapping all is alright.
The problem is that when @ojb.field are in header the attribute "access"
is ignored ( as described in doc ). 

Is there a way to work with this strategie of inheritance mapping and
xdoclet.

In the sample class B redefines attribute id, with @ojb.field at field
level, this works, but "id" of class "A" is hidden.

Thanks.



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: ojb, xdoclet and inheritance

Posted by Thomas Dudziak <to...@first.fhg.de>.
Nouguier Olivier wrote:

> Yes that's working
> 
> I'm debugging the job of a collegue, and I didn't find your solution. I
> think they have found (more) natural to try make a selection on the
> fields to override. 
> 
> I've not hack the xdoclet-ojb yet, but I suppose:
> 
>          1: with   include-inherited='true' you copy the fields from
> inherited class

Yes, per default (include-inherited='true') the XDoclet OJB module will 
copy all features from the class descriptors of the super classes into 
the current class descriptor.

>          2: with ignore true you then remove ignored field from list

That's one of the applications of @ojb.modify-inherited. This tag is 
basically used to modify one of the inherited features for the current 
class descriptor. You can change almost anything, e.g. the jdbc type or 
the column. Or you can set ignore='true' to state that you do not want 
this field in the current class descriptor.

Tom


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: ojb, xdoclet and inheritance

Posted by Nouguier Olivier <ol...@wanadoo.fr>.
On Thu, 2004-06-24 at 23:07, Thomas Dudziak wrote:
> Nouguier Olivier wrote:
> 
> > Hi all, and sorry for the wait ( my child needed a long story to sleep )
> 
> no problem, there are things that are more important than work :-)
> 
> I was wondering: why do you have include-inherited='false'? You should 
> be able to achieve what you want with @ojb.modify-inherited like this:

Yes that's working

I'm debugging the job of a collegue, and I didn't find your solution. I
think they have found (more) natural to try make a selection on the
fields to override. 

I've not hack the xdoclet-ojb yet, but I suppose:

         1: with   include-inherited='true' you copy the fields from
inherited class
         2: with ignore true you then remove ignored field from list

That could explain the way to proceed ?
 
 Your solution works perfectly, tomorow I will be a heros,  many many
thanks Tom

> package com.amdm.ojbdemo.model;
> 
> /**
>   * @ojb.class            table = "salaries"
>   * @ojb.reference        class-ref="com.amdm.ojbdemo.model.Person"
>   *                       foreignkey="id"
>   * @ojb.modify-inherited name="lastname"
>   *                       ignore="true"
>   * @ojb.modify-inherited name="firstname"
>   *                       ignore="true"
>   */
> public class Salary extends Person {
>          /** @ojb.field */
> 	private double income;
> 
> ...
> }
> 
> Leave the Person class as it is (esp. determine-extents='false') and you 
> should be fine.
> 
> Tom
> 
> ---------------------------------------------------------------------
> 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: ojb, xdoclet and inheritance

Posted by Thomas Dudziak <to...@first.fhg.de>.
Nouguier Olivier wrote:

> Hi all, and sorry for the wait ( my child needed a long story to sleep )

no problem, there are things that are more important than work :-)

I was wondering: why do you have include-inherited='false'? You should 
be able to achieve what you want with @ojb.modify-inherited like this:

package com.amdm.ojbdemo.model;

/**
  * @ojb.class            table = "salaries"
  * @ojb.reference        class-ref="com.amdm.ojbdemo.model.Person"
  *                       foreignkey="id"
  * @ojb.modify-inherited name="lastname"
  *                       ignore="true"
  * @ojb.modify-inherited name="firstname"
  *                       ignore="true"
  */
public class Salary extends Person {
         /** @ojb.field */
	private double income;

...
}

Leave the Person class as it is (esp. determine-extents='false') and you 
should be fine.

Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: ojb, xdoclet and inheritance

Posted by Nouguier Olivier <ol...@wanadoo.fr>.
Hi all, and sorry for the wait ( my child needed a long story to sleep )

Here are Person <---- Salary and the repository generated. 

The problem is on Salary(id) which is pk of salary and fk on
Persons(id). As Salary has no id ( it's inherited ) I have to put @field
in class metadoc ===> so access is anonymous as expected but I like to
keep the access value of inherited field



<class-descriptor
    class="com.amdm.ojbdemo.model.Salary"
    table="salaries"
>
    <field-descriptor
        name="id"
        column="id"
        jdbc-type="BIGINT"
        primarykey="true"
        access="anonymous"
    >

should become ( removal of access="anonymous" )

<class-descriptor
    class="com.amdm.ojbdemo.model.Salary"
    table="salaries"
>
    <field-descriptor
        name="id"
        column="id"
        jdbc-type="BIGINT"
        primarykey="true"
    >

I'd like to keep the access attribute of inherited field

Thanks

> > Using xdoclet for generating mapping file brings us to put an
> > @ojb.reference name="id" in Class B header, but for this to work we need
> > to declare id as anonymous field of B ( @ojb.field also in header ).
> > 
> > As consequence id of A is never filled with db data ( anonymous ). If we
> > change access="readonly" in mapping all is alright.
> > The problem is that when @ojb.field are in header the attribute "access"
> > is ignored ( as described in doc ). 
> > 
> > Is there a way to work with this strategie of inheritance mapping and
> > xdoclet.
> > 
> > In the sample class B redefines attribute id, with @ojb.field at field
> > level, this works, but "id" of class "A" is hidden.
> 
> Could you post the classes with the tags as you're using them, and the 
> repository_user.xml part as it is generated and as you'd like to have it ?
> 
> Tom
> 


Re: ojb, xdoclet and inheritance

Posted by Thomas Dudziak <to...@first.fhg.de>.
Nouguier Olivier wrote:

> Hi all,
>  We're using ojb in a big project, with many many inheritance relations.
> We choose the One Table per object strategie.
> 
> So:
> 
>  class A {
>   int id
>   int fieldA
> }
> 
>  Class B extends A {
>    int fieldB
> } 
> 
> Using xdoclet for generating mapping file brings us to put an
> @ojb.reference name="id" in Class B header, but for this to work we need
> to declare id as anonymous field of B ( @ojb.field also in header ).
> 
> As consequence id of A is never filled with db data ( anonymous ). If we
> change access="readonly" in mapping all is alright.
> The problem is that when @ojb.field are in header the attribute "access"
> is ignored ( as described in doc ). 
> 
> Is there a way to work with this strategie of inheritance mapping and
> xdoclet.
> 
> In the sample class B redefines attribute id, with @ojb.field at field
> level, this works, but "id" of class "A" is hidden.

Could you post the classes with the tags as you're using them, and the 
repository_user.xml part as it is generated and as you'd like to have it ?

Tom


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org