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 Ryan Harris <ry...@ryanharris.us> on 2005/11/16 03:04:09 UTC
Mapping Multiple Joined Tables
I'm getting unexpected results from my application and can't figure out
what I have configured improperly. I have mapped classes on muliple
joined tables in the simple example below which is very much similar to
the example in the documentation advanced-technique.
I have an A class and a B class that extends A. When I create a new B
object, then set the properties, and call commit using odmg, the
following is what is getting saved to my db tables as a result of a
single commit of a new B object.
Table A
id a_prop version
9 A prop 1
11 A prop 1
Table B
id b_prop a_id version
7 B prop 11 1
I wasn't expecting to get two rows in table A. Now, When I query for an
all A objects with an odmg query I can get two A objects instead of one
but I only save a single B object which should have one B row in the
database and one A row, I think?
-------------- CLASS A ---------------
public class A {
/** Creates a new instance of A */
public A() {
}
public Integer id;
public Integer getId(){ return id; }
public void setId(Integer value){ id=value; }
public String aprop;
public String getAprop(){
return aprop;
}
public void setAprop(String value){
aprop=value;
}
public Integer version;
public Integer getVersion(){ return version; }
public void setVersion(Integer value){
version=value;
}
-------------- CLASS B ---------------
public class B extends A{
/** Creates a new instance of B */
public B() {
}
public Integer id;
public Integer getId(){ return id; }
public void setId(Integer value){ id=value; }
public String bprop;
public String getBprop(){
return bprop;
}
public void setBprop(String value){
bprop=value;
}
public Integer version;
public Integer getVersion(){ return version; }
public void setVersion(Integer value){
version=value;
}
public Integer aid;
public Integer getAid(){ return aid; }
public void setAid(Integer value){ aid=value; }
}
------------Repository XML -----------
<class-descriptor class="org.A" table="a_table">
<field-descriptor name="id" column="id" jdbc-type="INTEGER"
sequence-name="seq_id" primarykey="true" autoincrement="true"
nullable="false"/>
<field-descriptor name="aprop" column="aprop" jdbc-type="VARCHAR"/>
<field-descriptor
name="version"
column="VERSION_MAINTAINED_BY_OJB"
jdbc-type="INTEGER"
locking="true"
/>
</class-descriptor>
<class-descriptor class="org.B" table="b_table">
<field-descriptor jdbc-type="INTEGER" name="id" column="id"
primarykey="true" sequence-name="seq_id" autoincrement="true"
nullable="false"/>
<field-descriptor jdbc-type="INTEGER" name="aid" column="aid"/>
<field-descriptor name="bprop" column="bprop" jdbc-type="VARCHAR"/>
<field-descriptor
name="version"
column="VERSION_MAINTAINED_BY_OJB"
jdbc-type="INTEGER"
locking="true"
/>
<reference-descriptor name="super"
class-ref="org.A"
auto-retrieve="true"
auto-update="true"
auto-delete="true">
<foreignkey field-ref="aid"/>
</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