So, let's say that the classes that implement this interface have nothing in common, 
than the fact that they implement the same interface (existing classes that are 
modified to implement this interface to give some commonality to them), so there are 
no common properties between them.

In this case, would that mean the only get/set I would need to define on the interface 
is for ojbConcreteClass?

I am so not sure how the the reference would work...the class that has the reference 
has a column for the FK to that referenced object, but should it also contain the 
objConcreteClass field to the class-type of the referenced object? This is were my 
confusion is.

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.

Thanks!


-----Original Message-----
From: Thomas Dudziak [mailto:[EMAIL PROTECTED]
Sent: Sun 6/20/2004 4:31 AM
To: OJB Users List
Subject: Re: How do you map a reference to an interface-backed class? (non-trivial)
 
Andrew Clute wrote:

> I have looked at all of the examples, I can't seem to make heads or 
> tails of how to handle my situation. I want to map a class that has a 
> reference to an object, that can one of many different objects, that all 
> implement the same interface.
> 
> Example
> 
> Interface A{
> 
> }
> 
> class B implements A
> {}
> 
> class C implements A
> {}
> 
> class Z
> {
>     private A myA;
> }
> 
> So, in this case, how do I map class Z since it's member variable is of 
> Type A, but I want the concrete object, either of Type B or C to be 
> filled in.
> 
> Seems like there is no known strategy to do this: "Using Interfaces With 
> OJB" talks about a similar situation, but assumes that there is only one 
> concrete class that can be instantiated for the reference (the 
> factory-method assumes that it will only return one concrete class type).
> 
> Seems like I need a combination of the Interface mapping, and the 
> 'ojbConcreteClass' property to have the appropriate concrete class 
> instantiated.

Yes, that should work. You define all common fields in the interface 
including ojbConcreteClass using getter/setter methods, and you need the 
PersistentFieldIntrospectorImpl or PersistentFieldAutoProxyImpl for the 
field access (OJB.properties) as there are no fields only bean methods.
You also should not need factory-class/factory-method now because OJB 
shouldn't try to instantiate the interface if ojbConcreteClass does not 
refer to it.

Tom


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to