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 gf...@fys.com.ar on 2003/09/19 16:53:19 UTC
Odd behaviour when updating properties from superclass only with odmg.
Hi all,
Let´s say we have a class Persona, -spanish property names between
brackets-.
Then we extend Person in a class Tecnico (coach) and class Jugador
(Player).
Just to make it simple we will focus in Tecnico class.
Superclass Persona has properties name (nombre), lastname (apellido),
weight (peso)
Class Tecnico has property title
Persona: nombre, apellido, peso (name, lastname,
weight)
/ \
extends / \
/ \
Tecnico Jugador
title jerseyNumber
In our app, we modify property peso (see code sample A) (weight) from a
given object Tecnico (coach); pls remember, property peso comes from
superclass Persona.
Then we save the modified Tecnico usign odmg and... the database does not
reflect the change.!!
Now, if we we also modify the property title from a given object Tecnico
(coach) (same tx) (uncommenting line Sample A.1), odmg works fine. The
database reflects all changes.
It seems we are having a problem here, when updating properties from an
extended class only.
We might be doing something wrong here, pls send us your comments.
Thanks in advance,
Gustavo Faerman
Buenos Aires, Argentina
Testbed: OJB rc4, HSQLDB.
*************************
Code Sample A
String oqlQuery = "select del from " + Tecnico.class().getName() +
" where ID_Persona = " + id;
Database db = odmg.getDatabase(null); // the current DB
Transaction tx = null;
try {
tx = odmg.newTransaction();
tx.begin();
OQLQuery query = odmg.newOQLQuery();
query.create(oqlQuery);
DList result = (DList)query.execute();
Tecnico toBeEdited = (Tecnico)result.get(0);
tx.lock(toBeEdited, Transaction.WRITE);
toBeEdited.setPeso(60);
// toBeEdited.setTitle(4); //Code Sample A.1
tx.commit();
}
catch (Throwable t) {
// rollback in case of errors
tx.abort();
t.printStackTrace();
}
******* Clase Persona ********
public class Persona {
private int ID_Persona;
private String nombre;
private String apellido;
private double peso;
/**
*@link aggregation
* @associates ar.com.fys.basketball.coach.entidades.Documento
* @supplierCardinality 0..**/
private ArrayList susDocumentos;
public int getID_Persona(){
return ID_Persona;
}
public void setID_Persona(int ID_Persona){
this.ID_Persona = ID_Persona;
}
public double getPeso(){ return peso; }
public void setPeso(double peso){ this.peso = peso; }
Other getters y setters removed...
}
******* Clase Tecnico ********
public class Tecnico extends Persona {
public int getID_Persona(){
return ID_Persona;
}
public void setID_Persona(int ID_Persona){
this.ID_Persona = ID_Persona;
}
public int getTitle(){
return title;
}
public void setTitle(int title){
this.title = title;
}
private int ID_Persona;
private int title;
}
****** Script tablas ********
CREATE TABLE Tecnico
(
title INTEGER,
ID_Persona INTEGER NOT NULL,
CONSTRAINT PK_Tecnico PRIMARY KEY (ID_Persona)
)
CREATE TABLE Persona
(
peso REAL,
nombre VARCHAR(20),
apellido VARCHAR(20),
ID_Persona INTEGER,
CONSTRAINT PK_Persona PRIMARY KEY (ID_Persona)
)
ALTER TABLE Tecnico ADD CONSTRAINT persona1 FOREIGN KEY (
ID_Persona
)
REFERENCES Persona (
ID_Persona
)
********** repository.xml ***********
<class-descriptor
class="ar.com.fys.basketball.coach.entidades.Persona"
table="Persona"
>
<field-descriptor
name="ID_Persona"
column="ID_Persona"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor
name="nombre"
column="nombre"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="apellido"
column="apellido"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="peso"
column="peso"
jdbc-type="DOUBLE"
/>
</class-descriptor>
<class-descriptor
class="ar.com.fys.basketball.coach.entidades.Tecnico"
table="Tecnico"
>
<field-descriptor
name="ID_Persona"
column="ID_Persona"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor
name="title"
column="title"
jdbc-type="INTEGER"
/>
<reference-descriptor
name="super"
auto-retrieve="true"
auto-update="true"
auto-delete="true"
class-ref="ar.com.fys.basketball.coach.entidades.Persona">
<foreignkey field-ref="ID_Persona" />
</reference-descriptor>
</class-descriptor>