-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem loading object in a many-to-one relationship
PostPosted: Tue Jun 20, 2006 10:36 am 
Newbie

Joined: Tue Jun 20, 2006 6:35 am
Posts: 1
Hi, I have a problem with my hibernate configuration. I can´t get an object using a many-to-one relationship.

I have two tables in my DB, with this mappings files:


Code:
<hibernate-mapping package="zonaprint.hibernate.mappings">
   <class
      name="Tbusuario"
      table="tbusuario"
   >
      <id
         name="Id"
         type="integer"
         column="idUser"
      >
         <generator class="native"/>
      </id>

      <set name="Tbcoleccions" inverse="true">
         <key column="idUser"/>
         <one-to-many class="Tbcoleccion"/>
      </set>
   </class>   
</hibernate-mapping>


and

Code:
<hibernate-mapping package="zonaprint.hibernate.mappings">
   <class
      name="Tbcoleccion"
      table="tbcoleccion"
   >
      <id
         name="Id"
         type="integer"
         column="idColeccion"
      >
         <generator class="native"/>
      </id>

      <property
         name="Nombre"
         column="nombre"
         type="string"
         not-null="true"
         length="100"
      />
      <many-to-one
         name="Usuario"
         column="usuario"
         class="Tbusuario"
         not-null="true"
      >
      </many-to-one>
   
   </class>   
</hibernate-mapping>


The problem appears when I try to get the object Tbusuario from an instance of a Tbcoleccion. The code is:

Code:
Tbcoleccion coleccion = new Tbcoleccion();
session.load(coleccion,new Integer(2));
      
Tbusuario user = coleccion.getUsuario();


This code doesn´t throws any exception, but it fails because the object Tbusuario it returns has all its fields null. Also I have seen that the object that returns is Tbusuario$$EnhancerByCGLIB$$.

While i was writing this lines I encountered a solution.
This is one way to solve this problem, It is adding lazy="false" in every many-to-one relationship at hibernate mapping files. I don´t know if its an hibernate bug (my version is 3.1.3).

I hope this will help someone who could have the same problem I had.

[/code]


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

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.