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 Stephan Wannenwetsch <wa...@reitec.de> on 2003/12/04 17:01:20 UTC
JDO inheritence
Hallo,
I'm trying to store an object which inherits some attributes from a
superclass, but values are only be inserted in the subclass table an
nothing is inserted in the superclass table.
Objectmodel:
Class BusinessPartner()
Integer bpid;
String attribute
Class Individual extends BusinessPartner()
String oneMoreAttribute;
To get it a little bit more complicated I use the JDO plugin my
JDO-Files look as follows:
==> Individual.jdo
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jdo PUBLIC "-//Sun Microsystems, Inc.//DTD Java Data
Objects Metadata 1.0//EN"
"http://java.sun.com/dtd/jdo_1_0.dtd">
<jdo>
<package name="demo.myshop.model.ojb">
<class name="Individual"
persistence-capable-superclass="demo.myshop.model.ojb.BusinessPartner">
<field name="fk_bpid" persistence-modifier="persistent"></field>
<field name="gender" persistence-modifier="persistent"></field>
</class>
</package>
</jdo>
==> BusinessPartner.jdo
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jdo PUBLIC "-//Sun Microsystems, Inc.//DTD Java Data
Objects Metadata 1.0//EN"
"http://java.sun.com/dtd/jdo_1_0.dtd">
<jdo>
<package name="demo.myshop.model.ojb">
<class name="BusinessPartner" identity-type="datastore">
<field name="Bpid" persistence-modifier="persistent"></field>
<field name="Adress" persistence-modifier="persistent"></field>
<field name="Name" persistence-modifier="persistent"></field>
</class>
</package>
</jdo>
The Repository.xml looks as follows:
<class-descriptor
class="demo.myshop.model.ojb.BusinessPartner"
table="OJB_BUSINESSPARTNER">
<field-descriptor
name="Bpid"
column="BPID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"/>
<field-descriptor
name="Adress"
column="ADRESS"
jdbc-type="VARCHAR"/>
<field-descriptor
name="Name"
column="NAME"
jdbc-type="VARCHAR"/>
</class-descriptor>
<class-descriptor
class="demo.myshop.model.ojb.Individual"
table="OJB_INDIVIDUAL">
<field-descriptor
name="fk_bpid"
column="FK_BPID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"/>
<field-descriptor
name="gender"
column="GENDER"
jdbc-type="VARCHAR"/>
<reference-descriptor name="super"
class-ref="demo.myshop.model.ojb.BusinessPartner">
<foreignkey field-ref="fk_bpid" />
</reference-descriptor>
</class-descriptor>
The source code:
//Individual Testdata
Individual ind0 = new Individual();
ind0.setAdress("Adress IND0");
ind0.setName("Name IND0");
ind0.setGender("male");
t.begin();
pm.makePersistent(ind0);
t.commit();
So the problem was that there is only an entry in the OJB_INDIVIDUAL
table an none in the OJB_BUSINESSPARTNER table.
I hope someone can help me !
Thanks,
Stephan
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: JDO inheritence
Posted by Thomas Mahler <th...@web.de>.
Hi Stephan,
In mapping an inheritance hierachy is not different for OJB/JDO. So if
you mapping is correct everything should work fine.
I've some questions regarding your classes and mapping:
Stephan Wannenwetsch wrote:
> Hallo,
>
> I'm trying to store an object which inherits some attributes from a
> superclass, but values are only be inserted in the subclass table an
> nothing is inserted in the superclass table.
>
> Objectmodel:
> Class BusinessPartner()
> Integer bpid;
> String attribute
Can't find "attribute" in the jdo file and in the repository?
where are the other attributes Bpid, Adress and Name?
do you really start your attribute names with upper case letters as
suggested by the .jdo and the repository.xml?
>
> Class Individual extends BusinessPartner()
> String oneMoreAttribute;
cant't find this attribute in the JDO file and the repository?
in this class the attributes seem to start with lower case letters
(fk_bpid, gender)?
Can you please post the exact layout of BusinessPartner and Individual.
Please also post the log file and any error messages you get.
thanks,
thomas
>
> To get it a little bit more complicated I use the JDO plugin my
> JDO-Files look as follows:
>
> ==> Individual.jdo
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE jdo PUBLIC "-//Sun Microsystems, Inc.//DTD Java Data
> Objects Metadata 1.0//EN"
> "http://java.sun.com/dtd/jdo_1_0.dtd">
> <jdo>
> <package name="demo.myshop.model.ojb">
> <class name="Individual"
> persistence-capable-superclass="demo.myshop.model.ojb.BusinessPartner">
> <field name="fk_bpid" persistence-modifier="persistent"></field>
> <field name="gender" persistence-modifier="persistent"></field>
> </class>
> </package>
> </jdo>
>
> ==> BusinessPartner.jdo
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE jdo PUBLIC "-//Sun Microsystems, Inc.//DTD Java Data
> Objects Metadata 1.0//EN"
> "http://java.sun.com/dtd/jdo_1_0.dtd">
> <jdo>
> <package name="demo.myshop.model.ojb">
> <class name="BusinessPartner" identity-type="datastore">
> <field name="Bpid" persistence-modifier="persistent"></field>
> <field name="Adress" persistence-modifier="persistent"></field>
> <field name="Name" persistence-modifier="persistent"></field>
> </class>
> </package>
> </jdo>
>
> The Repository.xml looks as follows:
>
> <class-descriptor
> class="demo.myshop.model.ojb.BusinessPartner"
> table="OJB_BUSINESSPARTNER">
> <field-descriptor
> name="Bpid"
> column="BPID"
> jdbc-type="INTEGER"
> primarykey="true"
> autoincrement="true"/>
> <field-descriptor
> name="Adress"
> column="ADRESS"
> jdbc-type="VARCHAR"/>
> <field-descriptor
> name="Name"
> column="NAME"
> jdbc-type="VARCHAR"/>
> </class-descriptor>
>
> <class-descriptor
> class="demo.myshop.model.ojb.Individual"
> table="OJB_INDIVIDUAL">
> <field-descriptor
> name="fk_bpid"
> column="FK_BPID"
> jdbc-type="INTEGER"
> primarykey="true"
> autoincrement="true"/>
> <field-descriptor
> name="gender"
> column="GENDER"
> jdbc-type="VARCHAR"/>
> <reference-descriptor name="super"
> class-ref="demo.myshop.model.ojb.BusinessPartner">
> <foreignkey field-ref="fk_bpid" />
> </reference-descriptor>
> </class-descriptor>
>
> The source code:
> //Individual Testdata
> Individual ind0 = new Individual();
> ind0.setAdress("Adress IND0");
> ind0.setName("Name IND0");
> ind0.setGender("male");
> t.begin();
> pm.makePersistent(ind0);
> t.commit();
>
> So the problem was that there is only an entry in the OJB_INDIVIDUAL
> table an none in the OJB_BUSINESSPARTNER table.
>
> I hope someone can help me !
>
> Thanks,
> Stephan
>
> ---------------------------------------------------------------------
> 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