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 Andrew Geery <ge...@doc.state.sc.us> on 2003/04/14 21:13:32 UTC
1:1 query using an extent
I am having trouble with the following 1:1 query.
Class AB is a super-class of class A (A is derived from AB). Classes A
and AB map to the same table.
Class C stores a reference to an object of class A (in an instance
variable named a).
The problem is that when I attempt to instantiate class C, an object of
class AB is created, not of type A (from watching the debug output).
Then I get an exception because an object of class AB is being assigned
to a variable of class A.
My question is: How do I get an object of class A rather than class AB
instantiated? I'm confused as to why it is not, given that in the
reference-descriptor element I am explicitly requesting an object of
type A. I suspect that I am missing an extent somewhere, but I just
don't see where it is.
Any help would be greatly appreciated.
Andrew
===================================================
The error looks like this:
[org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDefaultImpl]
ERROR: while set field:
object class[ C
target field: a
target field type: A
object value class: AB
object value: AB@...
[org.apache.ojb.broker.accesslayer.RsIterator] ERROR: Error setting
field:a in object:C
===================================================
In my repository.xml file, I have the following:
<class-descriptor
class="AB" ...
>
<extent-class class-ref="A" />
<field-descriptor
name="z"
column="Z"
jdbc-type="VARCHAR"
primarykey="true"
/>...
</class-descriptor>
<class-descriptor
class="A"...
>
<field-descriptor
name="z"
column="Z"
jdbc-type="VARCHAR"
primarykey="true"
/>...
</class-descriptor>
<class-descriptor
class="C"...
>
<field-descriptor
name="z"
column="Z"
jdbc-type="VARCHAR"
primarykey="true"
/>
<reference-descriptor
name="a"
class-ref="A"
>
<foreignkey field-ref="z"/>
</reference-descriptor>
</class-descriptor>
Re: 1:1 query using an extent
Posted by Thomas Mahler <th...@web.de>.
Hi Andrew,
1.
remove the line
<extent-class class-ref="A" />
from the AB class-descriptor.
2. If you do not like 1. you have to define the mapping of AB<-A
hierarchie to one table properly. Follow the steps in tutorial3.html
(mapping an inheritance hierarchie to one table). You will have to use a
special attribute ojbConcreteClass to help OJB to instantiate the proper
class.
cheers,
thomas
Andrew Geery wrote:
> I am having trouble with the following 1:1 query.
>
> Class AB is a super-class of class A (A is derived from AB). Classes A
> and AB map to the same table.
> Class C stores a reference to an object of class A (in an instance
> variable named a).
>
> The problem is that when I attempt to instantiate class C, an object of
> class AB is created, not of type A (from watching the debug output).
> Then I get an exception because an object of class AB is being assigned
> to a variable of class A.
>
> My question is: How do I get an object of class A rather than class AB
> instantiated? I'm confused as to why it is not, given that in the
> reference-descriptor element I am explicitly requesting an object of
> type A. I suspect that I am missing an extent somewhere, but I just
> don't see where it is.
>
> Any help would be greatly appreciated.
> Andrew
>
> ===================================================
>
> The error looks like this:
> [org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDefaultImpl]
> ERROR: while set field:
> object class[ C
> target field: a
> target field type: A
> object value class: AB
> object value: AB@...
> [org.apache.ojb.broker.accesslayer.RsIterator] ERROR: Error setting
> field:a in object:C
>
> ===================================================
>
> In my repository.xml file, I have the following:
>
> <class-descriptor
> class="AB" ...
> >
> <extent-class class-ref="A" />
> <field-descriptor
> name="z"
> column="Z"
> jdbc-type="VARCHAR"
> primarykey="true"
> />...
> </class-descriptor>
>
>
> <class-descriptor
> class="A"...
> >
> <field-descriptor
> name="z"
> column="Z"
> jdbc-type="VARCHAR"
> primarykey="true"
> />...
> </class-descriptor>
>
>
> <class-descriptor
> class="C"...
> >
> <field-descriptor
> name="z"
> column="Z"
> jdbc-type="VARCHAR"
> primarykey="true"
> />
> <reference-descriptor
> name="a"
> class-ref="A"
> >
> <foreignkey field-ref="z"/>
> </reference-descriptor>
> </class-descriptor>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>