-->
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.  [ 5 posts ] 
Author Message
 Post subject: Mapping question
PostPosted: Mon Jul 17, 2006 10:44 am 
Newbie

Joined: Tue Jan 31, 2006 5:22 pm
Posts: 6
Location: Argentina
Hi!!

i have a problem mapping 3 tables and need help.
Tables:

Code:
create table Aumentos ( aumentos_id int not null primary key, ....... )
create table Aumentos_Detalle ( aumentos_id int not null, mod_sec_cc_id int not null, mod_sec_especialidad_id int not null, primary key (aumentos_id, mod_sec_cc_id, mod_sec_especialidad_id) )
create table Aumentos_Valor ( aumentos_id int not null, mod_sec_cc_id int not null, mod_sec_especialidad_id int not null, mod_sec_plan_id int not null, primary key (aumentos_id, mod_sec_cc_id, mod_sec_especialidad_id, mod_sec_plan_id) )


Classes:
Aumento / AumentoDetalle / AumentoValor

Code:
public class Aumento extends ... implements ... {
   ....
   /** <AumentoDetalle> */
   private Set detalles = new HashSet();
   ....
}

Code:
public class AumentoDetalle extends ... implements ... {
   ....
   private SecundariaModalidad modalidadCentroCosto = null;
   private SecundariaModalidad modalidadEspecialidad = null;

   /** <AumentoValor> */
   private Set valores = new HashSet();
   ....
}

Code:
public class AumentoValor extends ... implements ... {
   ....
   private SecundariaModalidad modalidadCentroCosto = null;
   private SecundariaModalidad modalidadEspecialidad = null;
   private SecundariaModalidad modalidadPlan = null;
}


My doubts are:
Aumento and AumentoDetalle must have bidirectional associations ? if not, how could hibernate realize that in order
to insert a record in 'Aumentos_Valor' it needs Aumento's id in 'AumentoDetalle' ?
AumentoDetalle and AumentoValor should have bidirectional associations?

Thanks in advance,

Nicolas Gonzalez

P.S.: Sorry for my english!!
Code:
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 11:27 am 
Newbie

Joined: Tue Jul 11, 2006 5:14 am
Posts: 10
Location: Paris, France
Hola,
No siempre hay necesidad de declarar todas las relaciones, pero las que si que no puedes dejar de lado es declarar al padre y si lo he entendido bien Aumento es el abuelo que tiene un set de AumentoDetalle(padre) y este a su vez tiene un set de AumentoValor (nietos), en este caso quien has de declarar es AumentoDetalle en AumentoValor y en la tabla cambiarlo tambien para mantener esta escalera. sino lo que tienes es un padre y 2hermanos hijos con lo que
Code:
/** <AumentoValor> */
   private Set valores = new HashSet();

debiera estar directamente en el padre Aumento

Yo creo que una vez este esto claro si debe ser bidireccional o no ya se vara, paero ahora mismo la estructura de las clases y las tablas es contradictoria

Suerte


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 11:54 am 
Newbie

Joined: Tue Jan 31, 2006 5:22 pm
Posts: 6
Location: Argentina
Hi!! i'll answer the post in english and spanish....

Gracias por responder. Quiero hacer algunas aclaraciones:
Aumento es el abuelo, que tiene un Set de detalles y este a su vez tiene un Set de valores. La estructura esta bien (a mi parecer...) porque AumentoDetalle no sólo contiene los datos que comenté sino que tiene otros. A su vez, al borrar un AumentoDetalle deben borrarse sus valores...
Ahora, si hago bidireccional AumentoDetalle con AumentoValor cómo sería posible que se arrastre el id desde Aumento a AumentoDetalle y asi hasta AumentoValor? esa es mi duda...

Gracias!!

Thanks for answering!!! I'd like to make some explanations:
Aumento has a Set of AumentoDetalle and it has a Set of AumentoValor as well. I think that the model i designed is not wrong because AumentoDetalle not only has the properties i mentioned before.. and if i remove an AumentoDetalle, then Hibernate should remove its Set of AumentoValor. That's the desired behaviour!!!
The thing is: if i declare AumentoDetalle and AumentoValor as a bidirectional association, how could Hibernate carry Aumento's id to AumentoValor???

Thanks in advance!!!

Nicolas Gonzalez


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 9:56 am 
Newbie

Joined: Tue Jul 11, 2006 5:14 am
Posts: 10
Location: Paris, France
Ahora entiendo mejor tu estructura

Your AumentoValor has a direct reference to his grandfather besides going thru father of father
To me choices woud be
-Write a trigger to fill this column, that will keep the database integrity, and recover its value by adding generated to the property in the hbm mapping
-Make it so your java clases automatically call the AumentoValor.setAumento when AumentoDetalle.setAumento is called

Anyway duplicating information in the database always ends up with data inconsistency sooner or later, and is not that hard to do add a method getAumento in AumentoValor that returns
Code:
this.AumentoDetalle.getAumento()
if you really need it


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 12:37 pm 
Newbie

Joined: Tue Jan 31, 2006 5:22 pm
Posts: 6
Location: Argentina
I'm still having a problem mapping my classes. Something weird is happening and don't know why!!
The problem is:
When i call session.save(aumento); Hibernate would insert aumento and then insert each detalle and finally each valor
corresponding to the detalle mentioned. After inserting the records, Hibernate performs un update for each
valor, that's one of the weird things that happens. The other issue happens randomly, an exception is thrown:
org.hibernate.PropertyAccessException
:exception getting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) getter of ar.com.osde.sigma.model.consumo.aumento.AumentoDetalle.?
I did changed "hibernate.cglib.use_reflection_optimizer" property to false and nothing happens. It may be a common message
for this kind of exception...
If you pay attention carefully to the message of the exception you would see that the property refered that belongs to AumentoDetalle
is a question mark!!! (?). Can anyone tell me what does it mean? I debugged Hibernate sources but can't find the problem
or how to solve it if a problems exists....
In the lines below, i'm showing the class structure and mapping files...

I have three tables:
Code:
create table Aumentos ( aumentos_id int not null primary key, ....... )
create table Aumentos_Detalle ( aumentos_id int not null, mod_sec_cc_id int not null, mod_sec_especialidad_id int not null, primary key (aumentos_id, mod_sec_cc_id, mod_sec_especialidad_id) )
create table Aumentos_Valor ( aumentos_id int not null, mod_sec_cc_id int not null, mod_sec_especialidad_id int not null, mod_sec_plan_id int not null, primary key (aumentos_id, mod_sec_cc_id, mod_sec_especialidad_id, mod_sec_plan_id) , .... )


The classes:
Code:
public class Aumento extends ... implements ... {
   ....
   /** <AumentoDetalle> */
   private Set detalles = new HashSet();
   ....
}

Code:
public class AumentoDetalle extends ... implements ... {
   ....
   private SecundariaModalidad modalidadCentroCosto = null;
   private SecundariaModalidad modalidadEspecialidad = null;

   /** Bidirectional association */
   private Aumento aumento;

   /** <AumentoValor> */
   private Set valores = new HashSet();
   ....
}

Code:
public class AumentoValor extends ... implements ... {
   ....
   private SecundariaModalidad modalidadCentroCosto = null;
   private SecundariaModalidad modalidadEspecialidad = null;
   private SecundariaModalidad modalidadPlan = null;
}


And, finally the mapping files:
Aumento.hbm.xml
Code:
....
<set cascade="all,delete-orphan" name="detalles" lazy="true" inverse="true" >
    <key column="id_aumentos" foreign-key="true" not-null="true" update="false" />
    <one-to-many class="ar.com.osde.sigma.model.consumo.aumento.AumentoDetalle" />
</set>
....

AumentoDetalle.hbm.xml
Code:
....
<composite-id>
       <key-many-to-one name="aumento" column="id_aumentos"   />
       <key-many-to-one name="modalidadCentroCosto" column="id_mod_sec_cc"  />
       <key-many-to-one name="modalidadEspecialidad" column="id_mod_sec_especialidad" />
</composite-id>
...
<set cascade="all" name="valores" lazy="true" >
   <key foreign-key="true" not-null="true">
      <column name="id_aumentos" />
      <column name="id_mod_sec_cc" />
      <column name="id_mod_sec_especialidad" />
        </key>
         <one-to-many class="ar.com.osde.sigma.model.consumo.aumento.AumentoValor" />
</set>
....

AumentoValor.hbm.xml
Code:
....
<composite-id>
       <key-many-to-one name="modalidadPlan" column="id_mod_sec_plan"  />
       <key-many-to-one name="modalidadFilial" column="id_mod_sec_filial" />
</composite-id>
...


Any ideas?

Thanks in advance,

Nicolas Gonzalez
Buenos Aires - Argentina

P.S.: Sorry for my english!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.