-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem in many-to-one bidirection relationship
PostPosted: Mon Jul 02, 2007 4:23 pm 
Newbie

Joined: Mon Jul 02, 2007 4:13 pm
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 4:39 pm 
Newbie

Joined: Mon Jul 02, 2007 4:13 pm
Posts: 2
I should also tell that the error only happens when I try access the property in a diferent session from that in which Ive created it.

When I access it in the same session, It runs ok.

Francisco


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.