Re: Re: OJB not returning the correct child types.

"Virgo Smart" <[email protected]>
Newsgroups gmane.comp.jakarta.ojb.user
Message-ID <[email protected]>
Hello Armin,

Apologies for posting a repeat of a similar problem as mentioned in an earlier post. I had already posted this one before I recieved the reply to the earlier one.

Looking at the modified class descriptor, I see that the extent-class and anonymous fields are being dropped. I think this is ok. However I am not sure if the "super" reference descriptor can point to the primary key field descriptor of the parent class.

Wouldn't this mean that the PK in the BOOKS / TOYS table would also need to be a FK pointing to the PK of the THINGS table ? Wouldn't this be illegal in SQL ?

Thanks and Regards,
Gautam  


On Wed, 22 Nov 2006 Armin Waibel wrote :
>Hi Gautam,
>
>as said in my previous post in thread "OJB: Identity equals method impl." you should use the "normal" TPS inheritance without a FK field and without "extent-class" declaration within TPS (and don't override fields in the sub-classes):
>
><class-descriptor
>     class="Thing"
>     table="THINGS">
>
>     <field-descriptor
>         name="id"
>         column="ID"
>         jdbc-type="INTEGER"
>         primarykey="true"
>         autoincrement="true"
>         />
>
>     <field-descriptor
>         name="name"
>         column="NAME"
>         jdbc-type="VARCHAR"
>         size="255"
>         />
>
>     <field-descriptor
>         name="drawerId"
>         column="DRAWER_ID"
>         jdbc-type="INTEGER"
>         access="anonymous"
>         />
>
></class-descriptor>
>
><class-descriptor
>     class="Toy"
>     table="TOYS">
>
>     <field-descriptor
>         name="id"
>         column="ID"
>         jdbc-type="INTEGER"
>         primarykey="true"
>         autoincrement="false"
>         />
>
>     <field-descriptor
>         name="category"
>         column="CATEGORY"
>         jdbc-type="VARCHAR"
>         size="255"
>         />
>     </field-descriptor>
>
>     <reference-descriptor
>         name="super"
>         class-ref="Thing"
>     >
>         <foreignkey field-ref="id"/>
>     </reference-descriptor>
>
></class-descriptor>
>
><class-descriptor
>     class="Book"
>     table="BOOKS">
>
>     <field-descriptor
>         name="id"
>         column="ID"
>         jdbc-type="INTEGER"
>         primarykey="true"
>         autoincrement="false"
>         />
>
>     <field-descriptor
>         name="author"
>         column="AUTHOR"
>         jdbc-type="VARCHAR"
>         size="255"
>         />
>
>     <field-descriptor
>         name="isbnCode"
>         column="ISBN_CODE"
>         jdbc-type="VARCHAR"
>         size="255"
>         />
>
>     </field-descriptor>
>
>     <reference-descriptor
>         name="super"
>         class-ref="Thing"
>     >
>         <foreignkey field-ref="id"/>
>     </reference-descriptor>
>
></class-descriptor>
>
>
><class-descriptor
>     class="Drawer"
>     table="DRAWER">
>
>     <field-descriptor
>         name="id"
>         column="id"
>         jdbc-type="INTEGER"
>         primarykey="true"
>         autoincrement="true"
>         />
>
>     <collection-descriptor
>         name="stuffInDrawer"
>         element-class-ref="Thing"
>         >
>         <inverse-foreignkey field-ref="drawerId"/>
>     </collection-descriptor>
></class-descriptor>
>
>
>The FK field "drawerId" in class Thing (of the 1:n reference in Drawer) is declared as anonymous. Please read carefully the section about how anonymous keys work to avoid problems
>http://db.apache.org/ojb/docu/guides/advanced-technique.html#How+do
>
>regards,
>Armin
>
>Virgo Smart wrote:
>>Hello,
>>
>>I am facing an issue when trying to retrieve the Drawer object.
>>Instead of retrieving a collection of Toy and Book instances in the stuffInDrawer attribute, collection containing Thing instances is returned.
>>
>>Following is the class descriptor that is used.
>>
>><class-descriptor
>>     class="Thing"
>>     table="THINGS">
>>
>>    <extent-class class-ref="Toy"/>
>>    <extent-class class-ref="Book"/>
>>
>>     <field-descriptor
>>         name="id"
>>         column="ID"
>>         jdbc-type="INTEGER"
>>         primarykey="true"
>>         autoincrement="true"
>>         />
>>
>>     <field-descriptor
>>         name="name"
>>         column="NAME"
>>         jdbc-type="VARCHAR"
>>         size="255"
>>         />
>>
>>     <field-descriptor
>>         name="drawerId"
>>         column="DRAWER_ID"
>>         jdbc-type="INTEGER"
>>         access="anonymous"
>>         />
>>
>></class-descriptor>
>>
>><class-descriptor
>>     class="Toy"
>>     table="TOYS">
>>
>>     <field-descriptor
>>         name="id"
>>         column="ID"
>>         jdbc-type="INTEGER"
>>         primarykey="true"
>>         autoincrement="true"
>>         />
>>
>>     <field-descriptor
>>         name="category"
>>         column="CATEGORY"
>>         jdbc-type="VARCHAR"
>>         size="255"
>>         />
>>
>>     <field-descriptor
>>         name="parentThingId"
>>         column="THING_ID"
>>         jdbc-type="BIGINT"
>>         access="anonymous"
>>     >
>>     </field-descriptor>
>>
>>     <reference-descriptor
>>         name="super"
>>         class-ref="Thing"
>>     >
>>         <foreignkey field-ref="parentThingId"/>
>>     </reference-descriptor>
>>
>></class-descriptor>
>>
>><class-descriptor
>>     class="Book"
>>     table="BOOKS">
>>
>>     <field-descriptor
>>         name="id"
>>         column="ID"
>>         jdbc-type="INTEGER"
>>         primarykey="true"
>>         autoincrement="true"
>>         />
>>
>>     <field-descriptor
>>         name="author"
>>         column="AUTHOR"
>>         jdbc-type="VARCHAR"
>>         size="255"
>>         />
>>
>>     <field-descriptor
>>         name="isbnCode"
>>         column="ISBN_CODE"
>>         jdbc-type="VARCHAR"
>>         size="255"
>>         />
>>
>>     <field-descriptor
>>         name="parentThingId"
>>         column="THING_ID"
>>         jdbc-type="BIGINT"
>>         access="anonymous"
>>     >
>>     </field-descriptor>
>>
>>     <reference-descriptor
>>         name="super"
>>         class-ref="Thing"
>>     >
>>         <foreignkey field-ref="parentThingId"/>
>>     </reference-descriptor>
>>
>></class-descriptor>
>>
>>
>><class-descriptor
>>     class="Drawer"
>>     table="DRAWER">
>>
>>     <field-descriptor
>>         name="id"
>>         column="id"
>>         jdbc-type="INTEGER"
>>         primarykey="true"
>>         autoincrement="true"
>>         />
>>         <collection-descriptor
>>         name="stuffInDrawer"
>>         element-class-ref="Thing"
>>         >
>>         <inverse-foreignkey field-ref="drawerId"/>
>>     </collection-descriptor>
>></class-descriptor>
>>
>>
>>I have used the table per subclass hierarchy strategy.
>>I have used SequenceManagerHighLowImpl as the sequence manager. The ids (ID column) in the TOYS and BOOKS tables are unique when the Drawer object is stored. In the sense, when a Drawer containing 3 things (2 books and 1 toy) is stored, the ids stored in THINGS table are 1, 2, and 3, where as the ids stored in BOOKS table are 1 and 2 and id stored in the TOYS table is 3.
>>
>>I hope I have provided sufficient details to debug the issue. Could anyone please point me as to where am I going wrong or if there is any way to circumvent the problem ?
>>  Thanks and Regards,
>>Gautam.
>>
>>
>>  
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [email protected]
>For additional commands, e-mail: [email protected]
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.