You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by "Clute, Andrew" <An...@osn.state.oh.us> on 2004/06/21 15:42:04 UTC

RE: How do you map a reference to an interface-backed class? (non-trivial)

That's what I assumed, and was afraid of.

I think I can get around it temporarily by actually creating a composite
field that contains the classname and the PK in the same field (i.e.
"foo.bar.CatalogItem:12345"), and then creating a custom Conversion that
will take that string and instantiate the object.

Now, is there any technical reason why there isn't a strategy to map a
class that has a reference to an interface-backed class where the
concrete classes are not mapped in the same table? It would seem to me,
that such a feature could be implemented pretty straight-forward in the
current architecture (and I would be willing to take that on), but I
want to make sure I understand all of the ramifications of why this
isn't done at this time (feature never implemented?, won't work with
what we currently have?, etc.

One staight-forward approach would to modify the repostiroy_user.xml
definitions to allow the following type of mapping:

    <reference-descriptor
        name="interfaceItem"
        class-name-field-ref="interfaceClassName"
    >
        <foreignkey field-ref="interfaceGuid"/>
    </reference-descriptor>

<field-descriptor
        name="interfaceClassName"
        column="interface_class_name"
        jdbc-type="VARCHAR"
    />
 <field-descriptor
        name="interfaceGuid"
        column="interface_guid"
        jdbc-type="VARCHAR"
        access="anonymous"
    />

-Andrew


-----Original Message-----
From: Thomas Dudziak [mailto:tomdz@first.fhg.de] 
Sent: Sunday, June 20, 2004 10:17 AM
To: OJB Users List
Subject: Re: How do you map a reference to an interface-backed class?
(non-trivial)


> To give some more concrete to the example, here is what I have...I 
> have two different objects that already exist: Course and CatalogItem.

> Now at this point we need to start accepting payment for them, so I 
> have created an Order and OrderItem, and I want the OrderItem to be 
> able to contain either one of the objects. So I created a Sellable 
> interface, and Course and CatalogItem now implement them. So, I now 
> need to figure out how to map OrderItem so that when it is restored, 
> the right object (Course or CatalogItem) is created.

This will work if both Course and CatalogItem map to the same table. If
you require them to be in different tables, then you'll probably have to
do the loading manually. This means that you have the basic parts
(primary key, ojbConcreteClass) in the same table, and load the other
fields/references/collections on your own in the constructor of the
concrete subclass. This is a bit more involved though.

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-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: How do you map a reference to an interface-backed class? (non-trivial)

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi thomas, andrew,

i recently came across your discussion about mapping interfaces. the approach 
using a class-name-field is imo very interesting. i assume that the mapped 
classes only share a common interface and are not in the same extent-hierarchy 
in the repository. otherwise you would have a problem because ojb requires the 
pk to be unique within a hierarchy.

i think you should open a feature request in scarab so the idea does not get lost.

thanks
jakob

Thomas Dudziak wrote:

> Clute, Andrew wrote:
> 
>> That's what I assumed, and was afraid of.
>>
>> I think I can get around it temporarily by actually creating a composite
>> field that contains the classname and the PK in the same field (i.e.
>> "foo.bar.CatalogItem:12345"), and then creating a custom Conversion that
>> will take that string and instantiate the object.
>>
>> Now, is there any technical reason why there isn't a strategy to map a
>> class that has a reference to an interface-backed class where the
>> concrete classes are not mapped in the same table? It would seem to me,
>> that such a feature could be implemented pretty straight-forward in the
>> current architecture (and I would be willing to take that on), but I
>> want to make sure I understand all of the ramifications of why this
>> isn't done at this time (feature never implemented?, won't work with
>> what we currently have?, etc.
>>
>> One staight-forward approach would to modify the repostiroy_user.xml
>> definitions to allow the following type of mapping:
>>
>>    <reference-descriptor
>>        name="interfaceItem"
>>        class-name-field-ref="interfaceClassName"
>>    >
>>        <foreignkey field-ref="interfaceGuid"/>
>>    </reference-descriptor>
>>
>> <field-descriptor
>>        name="interfaceClassName"
>>        column="interface_class_name"
>>        jdbc-type="VARCHAR"
>>    />
>> <field-descriptor
>>        name="interfaceGuid"
>>        column="interface_guid"
>>        jdbc-type="VARCHAR"
>>        access="anonymous"
>>    />
>>
>>  
>>
> That would work, I guess, though I'd rather put the class name next to 
> the foreignkey:
> 
>    <reference-descriptor
>        name="interfaceItem"
>    >
>        <concreteClassName field-ref="interfaceClassName"/>
>        <foreignkey field-ref="interfaceGuid"/>
>    </reference-descriptor>
> 
> IMO this concept should be extended to collections as well 
> (inverse-concreteClassName) to get rid of the hard-coded 
> 'ojbConcreteClass' stuff. Might be a good use of anonymous fields, too.
> 
> And sure, if you want to have a go at it, by all means go ahead !
> 
> 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


How to do an outer join ?

Posted by Stefan Schlösser <ss...@intermediate.de>.
Hi,

suppose I have a table K and a table A where A has a fk_k: a foreign key 
to K.

I would like to select entries from A and for each element additional 
data if available from K.

I use a reportQuery and set A as sourceclass and set outer join for path
"" , i.e. outer join for table A only. Unfortunately, this does not seem
to work, i.e. the result is empty. How do I set OuterJoin for the 
sourceClass only ?

Thanks for any help or pointer to docs ..

Cheers,
   Stefan

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


Re: How do you map a reference to an interface-backed class? (non-trivial)

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi thomas, andrew,

i recently came across your discussion about mapping interfaces. the approach 
using a class-name-field is imo very interesting. i assume that the mapped 
classes only share a common interface and are not in the same extent-hierarchy 
in the repository. otherwise you would have a problem because ojb requires the 
pk to be unique within a hierarchy.

i think you should open a feature request in scarab so the idea does not get lost.

thanks
jakob

Thomas Dudziak wrote:

> Clute, Andrew wrote:
> 
>> That's what I assumed, and was afraid of.
>>
>> I think I can get around it temporarily by actually creating a composite
>> field that contains the classname and the PK in the same field (i.e.
>> "foo.bar.CatalogItem:12345"), and then creating a custom Conversion that
>> will take that string and instantiate the object.
>>
>> Now, is there any technical reason why there isn't a strategy to map a
>> class that has a reference to an interface-backed class where the
>> concrete classes are not mapped in the same table? It would seem to me,
>> that such a feature could be implemented pretty straight-forward in the
>> current architecture (and I would be willing to take that on), but I
>> want to make sure I understand all of the ramifications of why this
>> isn't done at this time (feature never implemented?, won't work with
>> what we currently have?, etc.
>>
>> One staight-forward approach would to modify the repostiroy_user.xml
>> definitions to allow the following type of mapping:
>>
>>    <reference-descriptor
>>        name="interfaceItem"
>>        class-name-field-ref="interfaceClassName"
>>    >
>>        <foreignkey field-ref="interfaceGuid"/>
>>    </reference-descriptor>
>>
>> <field-descriptor
>>        name="interfaceClassName"
>>        column="interface_class_name"
>>        jdbc-type="VARCHAR"
>>    />
>> <field-descriptor
>>        name="interfaceGuid"
>>        column="interface_guid"
>>        jdbc-type="VARCHAR"
>>        access="anonymous"
>>    />
>>
>>  
>>
> That would work, I guess, though I'd rather put the class name next to 
> the foreignkey:
> 
>    <reference-descriptor
>        name="interfaceItem"
>    >
>        <concreteClassName field-ref="interfaceClassName"/>
>        <foreignkey field-ref="interfaceGuid"/>
>    </reference-descriptor>
> 
> IMO this concept should be extended to collections as well 
> (inverse-concreteClassName) to get rid of the hard-coded 
> 'ojbConcreteClass' stuff. Might be a good use of anonymous fields, too.
> 
> And sure, if you want to have a go at it, by all means go ahead !
> 
> 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-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: How do you map a reference to an interface-backed class? (non-trivial)

Posted by Thomas Dudziak <to...@first.fhg.de>.
Clute, Andrew wrote:

>That's what I assumed, and was afraid of.
>
>I think I can get around it temporarily by actually creating a composite
>field that contains the classname and the PK in the same field (i.e.
>"foo.bar.CatalogItem:12345"), and then creating a custom Conversion that
>will take that string and instantiate the object.
>
>Now, is there any technical reason why there isn't a strategy to map a
>class that has a reference to an interface-backed class where the
>concrete classes are not mapped in the same table? It would seem to me,
>that such a feature could be implemented pretty straight-forward in the
>current architecture (and I would be willing to take that on), but I
>want to make sure I understand all of the ramifications of why this
>isn't done at this time (feature never implemented?, won't work with
>what we currently have?, etc.
>
>One staight-forward approach would to modify the repostiroy_user.xml
>definitions to allow the following type of mapping:
>
>    <reference-descriptor
>        name="interfaceItem"
>        class-name-field-ref="interfaceClassName"
>    >
>        <foreignkey field-ref="interfaceGuid"/>
>    </reference-descriptor>
>
><field-descriptor
>        name="interfaceClassName"
>        column="interface_class_name"
>        jdbc-type="VARCHAR"
>    />
> <field-descriptor
>        name="interfaceGuid"
>        column="interface_guid"
>        jdbc-type="VARCHAR"
>        access="anonymous"
>    />
>
>  
>
That would work, I guess, though I'd rather put the class name next to 
the foreignkey:

    <reference-descriptor
        name="interfaceItem"
    >
        <concreteClassName field-ref="interfaceClassName"/>
        <foreignkey field-ref="interfaceGuid"/>
    </reference-descriptor>

IMO this concept should be extended to collections as well 
(inverse-concreteClassName) to get rid of the hard-coded 
'ojbConcreteClass' stuff. Might be a good use of anonymous fields, too.

And sure, if you want to have a go at it, by all means go ahead !

Tom


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


Re: How do you map a reference to an interface-backed class? (non-trivial)

Posted by Thomas Dudziak <to...@first.fhg.de>.
Clute, Andrew wrote:

>That's what I assumed, and was afraid of.
>
>I think I can get around it temporarily by actually creating a composite
>field that contains the classname and the PK in the same field (i.e.
>"foo.bar.CatalogItem:12345"), and then creating a custom Conversion that
>will take that string and instantiate the object.
>
>Now, is there any technical reason why there isn't a strategy to map a
>class that has a reference to an interface-backed class where the
>concrete classes are not mapped in the same table? It would seem to me,
>that such a feature could be implemented pretty straight-forward in the
>current architecture (and I would be willing to take that on), but I
>want to make sure I understand all of the ramifications of why this
>isn't done at this time (feature never implemented?, won't work with
>what we currently have?, etc.
>
>One staight-forward approach would to modify the repostiroy_user.xml
>definitions to allow the following type of mapping:
>
>    <reference-descriptor
>        name="interfaceItem"
>        class-name-field-ref="interfaceClassName"
>    >
>        <foreignkey field-ref="interfaceGuid"/>
>    </reference-descriptor>
>
><field-descriptor
>        name="interfaceClassName"
>        column="interface_class_name"
>        jdbc-type="VARCHAR"
>    />
> <field-descriptor
>        name="interfaceGuid"
>        column="interface_guid"
>        jdbc-type="VARCHAR"
>        access="anonymous"
>    />
>
>  
>
That would work, I guess, though I'd rather put the class name next to 
the foreignkey:

    <reference-descriptor
        name="interfaceItem"
    >
        <concreteClassName field-ref="interfaceClassName"/>
        <foreignkey field-ref="interfaceGuid"/>
    </reference-descriptor>

IMO this concept should be extended to collections as well 
(inverse-concreteClassName) to get rid of the hard-coded 
'ojbConcreteClass' stuff. Might be a good use of anonymous fields, too.

And sure, if you want to have a go at it, by all means go ahead !

Tom


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