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 Piet Molenaar <p....@amc.uva.nl> on 2005/06/07 11:03:11 UTC
Inheritance on multiple tables produces base class instances
Hi All,
I've implemented inheritance on multiple tables and it works fine for
inserting data. (see code snippets below)
(ojb is a great initiative and its elegance saves a lot of work!)
However, a problem arose when I tried to query for a dao without knowing
beforehand which type of object I will retrieve;
loading a referenced object always produces base class instances.
I've been looking around the archives and found this thread but the last
post mentioned a work-around by
storing an additional
id
http://nagoya.apache.org/eyebrowse/BrowseList?listId=107&by=thread&from=899091
Is this regular behavior or am I missing something (I can imagine that
proxy="dynamic" does not work?)
Thanks a lot in advance!
Piet
Explanation:
A source has a type of interaction which can be of a subtype
proteininteraction (in fact it is an inheritance tree of several types).
When querying the source with a proteininteraction for its interactiontype
I always get the base class InteractionTypeInterface retrieved.
I'm using OJB 1.0.3
// Dao's
public class Source
implements SourceInterface
{
private Integer dataid;
private String sourceid;
private InteractionTypeInterface interactiontype;
public Source()
{
targets = new Vector();
interactiontype = new InteractionType();
datatype = new DataType();
origin = new Origin();
}
//getters/setters
}
public class InteractionType implements InteractionTypeInterface, DAOInterface
{
protected Integer interactiontypeid;
protected String interactioninfo;
//getters/setters
}
public class ProteinInteractionType extends InteractionType implements
ProteinInteractionTypeInterface
{
protected String proteininteractioninfo;
//getters/setters
}
// Repository
<!-- Source contains the information about the datasource -->
<class-descriptor
class="amcplugin.data.persistency.Source"
proxy="dynamic"
table="SOURCE"
>
<field-descriptor id="1"
name="dataid"
column="DATA_ID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor id="6"
name="interactiontypeid"
column="INTERACTION_TYPE_ID"
jdbc-type="INTEGER"
access="anonymous"
/>
<reference-descriptor name="interactiontype"
class-ref="amcplugin.data.persistency.InteractionType"
auto-retrieve="true"
auto-update="true"
auto-delete="false"
>
<foreignkey field-ref="interactiontypeid"/>
</reference-descriptor>
</class-descriptor>
<!-- InteractionType links the id to the type of Interaction -->
<class-descriptor
class="amcplugin.data.persistency.InteractionType"
proxy="dynamic"
table="INTERACTION_TYPE"
>
<field-descriptor id="1"
name="interactiontypeid"
column="INTERACTION_TYPE_ID"
jdbc-type="INTEGER"
autoincrement="true"
primarykey="true"
/>
<field-descriptor id="2"
name="interactioninfo"
column="INTERACTION_INFO"
jdbc-type="VARCHAR"
/>
</class-descriptor>
<!-- ProteinInteractionInfo gives type of proteininteraction -->
<class-descriptor
class="amcplugin.data.persistency.ProteinInteractionType"
proxy="dynamic"
table="PROTEIN_INTERACTION_TYPE"
>
<field-descriptor id="1"
name="interactiontypeid"
column="INTERACTION_TYPE_ID"
jdbc-type="INTEGER"
autoincrement="true"
primarykey="true"
/>
<field-descriptor id="2"
name="proteininteractioninfo"
column="PROTEIN_INTERACTION_INFO"
jdbc-type="VARCHAR"
/>
<reference-descriptor name="super"
class-ref="amcplugin.data.persistency.InteractionType"
auto-retrieve="true"
auto-update="true"
auto-delete="object"
>
<foreignkey field-ref="interactiontypeid"/>
</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
Re: Inheritance on multiple tables produces base class
instances
Posted by Piet Molenaar <p....@amc.uva.nl>.
The release notes: the one place I should have looked but did not! ;)
I hope this can be fixed in the next release otherwise I have to elaborate
on the current work-around.
All the best and thanks for the efforts,
Piet
At 10:43 PM 6/7/2005, you wrote:
>Hi Piet,
>the work-around was only a suggestion to solve the problem temporary (for
>my case, it works well).
>I think this is a known issue (see
>http://db.apache.org/ojb/release-notes.txt), that will be fixed in version
>1.0.4 (correct me if I am wrong ;-)
>
>Best regards,
>Michael
>
>Piet Molenaar schrieb:
>
>>Hi All,
>>
>>I've implemented inheritance on multiple tables and it works fine for
>>inserting data. (see code snippets below)
>>(ojb is a great initiative and its elegance saves a lot of work!)
>>However, a problem arose when I tried to query for a dao without knowing
>>beforehand which type of object I will retrieve;
>>loading a referenced object always produces base class instances.
>>
>>I've been looking around the archives and found this thread but the last
>>post mentioned a work-around by
>>storing an additional id
>>http://nagoya.apache.org/eyebrowse/BrowseList?listId=107&by=thread&from=899091
>>Is this regular behavior or am I missing something (I can imagine that
>>proxy="dynamic" does not work?)
>>
>>Thanks a lot in advance!
>>
>>Piet
>>
>>Explanation:
>>A source has a type of interaction which can be of a subtype
>>proteininteraction (in fact it is an inheritance tree of several types).
>>When querying the source with a proteininteraction for its
>>interactiontype I always get the base class InteractionTypeInterface retrieved.
>>I'm using OJB 1.0.3
>>
>>// Dao's
>>
>>public class Source
>> implements SourceInterface
>>{
>> private Integer dataid;
>> private String sourceid;
>> private InteractionTypeInterface interactiontype;
>>
>> public Source()
>> {
>> targets = new Vector();
>> interactiontype = new InteractionType();
>> datatype = new DataType();
>> origin = new Origin();
>> }
>> //getters/setters
>>}
>>
>>public class InteractionType implements InteractionTypeInterface,
>>DAOInterface
>>{
>> protected Integer interactiontypeid;
>> protected String interactioninfo;
>> //getters/setters
>>}
>>
>>public class ProteinInteractionType extends InteractionType implements
>>ProteinInteractionTypeInterface
>>{
>> protected String proteininteractioninfo;
>>
>> //getters/setters
>>}
>>
>>// Repository
>>
>> <!-- Source contains the information about the datasource -->
>> <class-descriptor
>> class="amcplugin.data.persistency.Source"
>> proxy="dynamic"
>> table="SOURCE"
>> >
>> <field-descriptor id="1"
>> name="dataid"
>> column="DATA_ID"
>> jdbc-type="INTEGER"
>> primarykey="true"
>> autoincrement="true"
>> />
>> <field-descriptor id="6"
>> name="interactiontypeid"
>> column="INTERACTION_TYPE_ID"
>> jdbc-type="INTEGER"
>> access="anonymous"
>> />
>> <reference-descriptor name="interactiontype"
>> class-ref="amcplugin.data.persistency.InteractionType"
>> auto-retrieve="true"
>> auto-update="true"
>> auto-delete="false"
>> >
>> <foreignkey field-ref="interactiontypeid"/>
>> </reference-descriptor>
>> </class-descriptor>
>>
>> <!-- InteractionType links the id to the type of Interaction -->
>> <class-descriptor
>> class="amcplugin.data.persistency.InteractionType"
>> proxy="dynamic"
>> table="INTERACTION_TYPE"
>> >
>> <field-descriptor id="1"
>> name="interactiontypeid"
>> column="INTERACTION_TYPE_ID"
>> jdbc-type="INTEGER"
>> autoincrement="true"
>> primarykey="true"
>> />
>> <field-descriptor id="2"
>> name="interactioninfo"
>> column="INTERACTION_INFO"
>> jdbc-type="VARCHAR"
>> />
>> </class-descriptor>
>>
>> <!-- ProteinInteractionInfo gives type of proteininteraction -->
>> <class-descriptor
>> class="amcplugin.data.persistency.ProteinInteractionType"
>> proxy="dynamic"
>> table="PROTEIN_INTERACTION_TYPE"
>> >
>> <field-descriptor id="1"
>> name="interactiontypeid"
>> column="INTERACTION_TYPE_ID"
>> jdbc-type="INTEGER"
>> autoincrement="true"
>> primarykey="true"
>> />
>> <field-descriptor id="2"
>> name="proteininteractioninfo"
>> column="PROTEIN_INTERACTION_INFO"
>> jdbc-type="VARCHAR"
>> />
>> <reference-descriptor name="super"
>> class-ref="amcplugin.data.persistency.InteractionType"
>> auto-retrieve="true"
>> auto-update="true"
>> auto-delete="object"
>> >
>> <foreignkey field-ref="interactiontypeid"/>
>> </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
>>
>
>
>---------------------------------------------------------------------
>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
Re: Inheritance on multiple tables produces base class instances
Posted by Michael Baetgen <mi...@baetgen.com>.
Hi Piet,
the work-around was only a suggestion to solve the problem temporary
(for my case, it works well).
I think this is a known issue (see
http://db.apache.org/ojb/release-notes.txt), that will be fixed in
version 1.0.4 (correct me if I am wrong ;-)
Best regards,
Michael
Piet Molenaar schrieb:
> Hi All,
>
> I've implemented inheritance on multiple tables and it works fine for
> inserting data. (see code snippets below)
> (ojb is a great initiative and its elegance saves a lot of work!)
> However, a problem arose when I tried to query for a dao without
> knowing beforehand which type of object I will retrieve;
> loading a referenced object always produces base class instances.
>
> I've been looking around the archives and found this thread but the
> last post mentioned a work-around by
> storing an additional id
> http://nagoya.apache.org/eyebrowse/BrowseList?listId=107&by=thread&from=899091
>
> Is this regular behavior or am I missing something (I can imagine that
> proxy="dynamic" does not work?)
>
> Thanks a lot in advance!
>
> Piet
>
> Explanation:
> A source has a type of interaction which can be of a subtype
> proteininteraction (in fact it is an inheritance tree of several types).
> When querying the source with a proteininteraction for its
> interactiontype I always get the base class InteractionTypeInterface
> retrieved.
> I'm using OJB 1.0.3
>
> // Dao's
>
> public class Source
> implements SourceInterface
> {
> private Integer dataid;
> private String sourceid;
> private InteractionTypeInterface interactiontype;
>
> public Source()
> {
> targets = new Vector();
> interactiontype = new InteractionType();
> datatype = new DataType();
> origin = new Origin();
> }
> //getters/setters
> }
>
> public class InteractionType implements InteractionTypeInterface,
> DAOInterface
> {
> protected Integer interactiontypeid;
> protected String interactioninfo;
> //getters/setters
> }
>
> public class ProteinInteractionType extends InteractionType implements
> ProteinInteractionTypeInterface
> {
> protected String proteininteractioninfo;
>
> //getters/setters
> }
>
> // Repository
>
> <!-- Source contains the information about the datasource -->
> <class-descriptor
> class="amcplugin.data.persistency.Source"
> proxy="dynamic"
> table="SOURCE"
> >
> <field-descriptor id="1"
> name="dataid"
> column="DATA_ID"
> jdbc-type="INTEGER"
> primarykey="true"
> autoincrement="true"
> />
> <field-descriptor id="6"
> name="interactiontypeid"
> column="INTERACTION_TYPE_ID"
> jdbc-type="INTEGER"
> access="anonymous"
> />
> <reference-descriptor name="interactiontype"
> class-ref="amcplugin.data.persistency.InteractionType"
> auto-retrieve="true"
> auto-update="true"
> auto-delete="false"
> >
> <foreignkey field-ref="interactiontypeid"/>
> </reference-descriptor>
> </class-descriptor>
>
> <!-- InteractionType links the id to the type of Interaction -->
> <class-descriptor
> class="amcplugin.data.persistency.InteractionType"
> proxy="dynamic"
> table="INTERACTION_TYPE"
> >
> <field-descriptor id="1"
> name="interactiontypeid"
> column="INTERACTION_TYPE_ID"
> jdbc-type="INTEGER"
> autoincrement="true"
> primarykey="true"
> />
> <field-descriptor id="2"
> name="interactioninfo"
> column="INTERACTION_INFO"
> jdbc-type="VARCHAR"
> />
> </class-descriptor>
>
> <!-- ProteinInteractionInfo gives type of proteininteraction -->
> <class-descriptor
> class="amcplugin.data.persistency.ProteinInteractionType"
> proxy="dynamic"
> table="PROTEIN_INTERACTION_TYPE"
> >
> <field-descriptor id="1"
> name="interactiontypeid"
> column="INTERACTION_TYPE_ID"
> jdbc-type="INTEGER"
> autoincrement="true"
> primarykey="true"
> />
> <field-descriptor id="2"
> name="proteininteractioninfo"
> column="PROTEIN_INTERACTION_INFO"
> jdbc-type="VARCHAR"
> />
> <reference-descriptor name="super"
> class-ref="amcplugin.data.persistency.InteractionType"
> auto-retrieve="true"
> auto-update="true"
> auto-delete="object"
> >
> <foreignkey field-ref="interactiontypeid"/>
> </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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org