db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Clute, Andrew" <Andrew.Cl...@osn.state.oh.us>
Subject RE: How do you map a reference to an interface-backed class? (non-trivial)
Date Mon, 21 Jun 2004 13:42:04 GMT
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:

        <foreignkey field-ref="interfaceGuid"/>



-----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?

> 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.


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

View raw message