Hi,
Im using hibernate with HSQLDB, and Im having a problem with a one-to-many relationship between classes that inherit from tha same superclass.
The class hierarchy Im using is this one
Code:
public class MovTransferenciaCampoSaida extends MovTransferenciaCampo {
private MovTransferenciaCampoEntrada movCorrespondente = null;
MovTransferenciaCampoSaida() {
super();
}
public MovTransferenciaCampoSaida(
Campo campo, TipoInsercaoTransferencia tipoInsercao, Date data, String observacoes) {
super(campo, TipoMovTransferencia.MOV_TRANSF_SAIDA, tipoInsercao, data, observacoes);
}
public MovTransferenciaCampoEntrada getMovCorrespondente() {
return movCorrespondente;
}
public void setMovCorrespondente(MovTransferenciaCampoEntrada movCorrespondente) {
this.movCorrespondente = movCorrespondente;
}
}
public class MovTransferenciaCampoEntrada extends MovTransferenciaCampo {
private Set<MovTransferenciaCampoSaida> movsCorrespondentes = new HashSet<MovTransferenciaCampoSaida>();
MovTransferenciaCampoEntrada() {
super();
}
public MovTransferenciaCampoEntrada(
Campo campo, TipoInsercaoTransferencia tipoInsercao, Date data, String observacoes) {
super(campo, TipoMovTransferencia.MOV_TRANSF_ENTRADA, tipoInsercao, data, observacoes);
}
public Set<MovTransferenciaCampoSaida> getMovsCorrespondentes() {
return this.movsCorrespondentes;
}
public void setMovsCorrespondentes(
Set<MovTransferenciaCampoSaida> movsCorrespondentes) {
this.movsCorrespondentes = movsCorrespondentes;
}
public void associarMovCorrespondente(MovTransferenciaCampoSaida movCorrespondente) {
this.movsCorrespondentes.add(movCorrespondente);
movCorrespondente.setMovCorrespondente(this);
}
}
Im using the following mapping file:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="manejo.grupos.MovTransferenciaCampo" table="MOVCAMPO" abstract="true">
<id name="id" column="MOVCAMPO_ID">
<generator class="sequence"/>
</id>
<property name="data" type="timestamp" column="DATA"/>
<property name="observacoes"/>
<set name="animais" inverse="false" table="MOVCAMPO_ANIMAL">
<key column="MOVCAMPO_ID"/>
<many-to-many column="ANIMAL_ID"
class="manejo.animal.Animal"/>
</set>
<many-to-one name="campo"
column="ID_CAMPO"
not-null="false"
lazy="false"/>
<property name="tipo"
type="hibernate.HibTipoMovTransferencia"
not-null="false"/>
<property name="tipoInsercao"
type="hibernate.HibTipoInsercaoTransferencia"
not-null="false"/>
<union-subclass name="manejo.grupos.MovTransferenciaCampoEntrada" table="MOVTRANSFCAMPOENTRADA">
<set name="movsCorrespondentes" inverse="false" lazy="true">
<key column="MOVCAMPOENTRADA_ID" not-null="false"/>
<one-to-many class="manejo.grupos.MovTransferenciaCampoSaida"/>
</set>
</union-subclass>
<union-subclass name="manejo.grupos.MovTransferenciaCampoSaida" table="MOVTRANSFCAMPOSAIDA">
<many-to-one name="movCorrespondente"
column="MOVCAMPOENTRADA_ID"
not-null="false"/>
</union-subclass>
</class>
</hibernate-mapping>
It works well, until I try to access the field
MovTransfCampoEntrada->movsCorrespondentes. The expected behavior would be to receive a set from MovTransfCampoSaida objects, but it returns a set from MovTransfCampoEntrada objects!
I dont know what could be going wrong. Does anybody can help me?
Thanks in advance,
Francisco