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.  [ 11 posts ] 
Author Message
 Post subject: [Hibernate 3.1.3]: Not loading many-to-one relationship.
PostPosted: Tue May 16, 2006 5:37 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
Hibernate version: 3.1.3
Name and version of the database you are using: Postgres 8.1.1

Hello, I'm having a curious problem while migrating from Hibernate 2.1.8 to 3.1.3. I have follow Migration Guide's instructions and the migration is almost done, except for one single mapping: a many-to-one with lazy="true" aren't load when I get the root objetc.

My mappings are below:

The root object that I'm retrieving:
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 default-lazy="false"  schema="Atendimento">

   <class name="com.mycompany.system.model.Mesa">
      
      <id name="id" column="id" type="long" unsaved-value="-1">
         <generator class="increment"/>
      </id>

      ....

      <many-to-one
         lazy="false"
         name="atendente"
         column="atendente"/>

      ...

   </class>
</hibernate-mapping>

Mapping for "atendente" relationship:
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 default-lazy="false"  schema="Atendimento">

   <class name="com.mycompany.system.model.Atendente">
      
      <id name="id" column="id" type="long" unsaved-value="-1">
         <generator class="increment"/>
      </id>
      
      <many-to-one name="usuario" column="id_usuario" lazy="false"/>
      
      ...

   </class>
</hibernate-mapping>

And mapping for "usuario" (the class is a subclass from an access control infrainstructure):
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 default-lazy="false"  schema = "ControleAcesso">

   <class name="com.mycompany.system.accesscontrol.AControlEntity" lazy="false">

      <id name="id" unsaved-value="-1">
         <generator class="increment"/>
      </id>
      
      <set name="permissions" lazy="true">
         <key column="permission_id"/>
         <one-to-many class="com.mycompany.system.accesscontrol.tbfunction.TBFunction"/>
      </set>

      <joined-subclass name="com.mycompany.system.user.TBUser" lazy="false">
      
         <key column="ID"/>
         
         <property name="login" not-null="true" unique="true"/>
         
         ...
         
      </joined-subclass>
      
   </class>
   
</hibernate-mapping>


When I load a "Mesa" object, all properties from "Mesa" and "atendente" are correctly load, except "usuario" that comes null, but _there is_ a register in database for user. I have take a look at the following links:
http://opensource.atlassian.com/project ... e/HHH-1435

But this doesn't help.

Section 5.1.11 from the manual says that "lazy="false" specifies that the association will always be eagerly fetched. Note that if constrained="false", proxying is impossible and Hibernate will eager fetch the association!". If I put:
Code:
<many-to-one name="usuario" column="id_usuario" lazy="false"/>

"usuario" must be load when "atendente" were load, don't?

The HQL used to load "mesa" is:
Code:
from
   Mesa mesa
left join fetch
   mesa.atendente atendente
left join fetch
   atendente.usuario usuario
where
   mesa.agencia.id=?

That generates the SQL query below:
Code:
select mesa0_.id as id103_0_,
   atendente1_.id as id158_1_,
   tbuser2_.ID as id87_2_,
   mesa0_.data as data103_0_,
   mesa0_.id_agencia as id3_103_0_,
   mesa0_.mesa_unit as mesa4_103_0_,
   mesa0_.atendente as atendente103_0_,
   mesa0_.status as status103_0_,
   mesa0_.data_abertura as data7_103_0_,
   mesa0_.usuario_abertura as usuario8_103_0_,
   mesa0_.data_fechamento as data9_103_0_,
   mesa0_.usuario_fechamento as usuario10_103_0_,
   mesa0_.data_inicio_status as data11_103_0_,
   mesa0_2_.senha_atual as senha2_105_0_,
   mesa0_2_.numero_atendimento as numero3_105_0_,
   case
      when mesa0_1_.id is not null then 1
      when mesa0_2_.id is not null then 2
      when mesa0_.id is not null then 0
   end as clazz_0_,
   atendente1_.id_usuario as id2_158_1_,
   tbuser2_.login as login91_2_,
   tbuser2_.password as password91_2_,
   tbuser2_.registration as registra4_91_2_,
   tbuser2_.name as name91_2_,
   tbuser2_.apelido as apelido91_2_,
   tbuser2_.nivel as nivel91_2_,
   tbuser2_.idioma as idioma91_2_,
   tbuser2_.branch as branch91_2_,
   tbuser2_.jobFunction as jobFunc10_91_2_
from Atendimento.Mesa mesa0_
left outer join
   Atendimento.mesa_recepcao mesa0_1_ on mesa0_.id=mesa0_1_.id
left outer join
   Atendimento.mesa_atendimento mesa0_2_ on mesa0_.id=mesa0_2_.id
left outer join
   Atendimento.Atendente atendente1_ on mesa0_.atendente=atendente1_.id
left outer join
   ControleAcesso.TBUser tbuser2_ on atendente1_.id_usuario=tbuser2_.ID
left outer join
   ControleAcesso.AControlEntity tbuser2_1_ on tbuser2_.ID=tbuser2_1_.id
where mesa0_.id_agencia=?)

As you can see, I'm trying to use join fetch to load "usuario" in a single query, but without success. What am I doing wrong?

Kind Regards,

Full stack trace of any exception that occurs:
Code:
java.lang.NullPointerException
   at com.mycompany.system.model.Atendente.getLogin(Atendente.java:105)
   at com.mycompany.system.rmi.ServidorAtendimento.getMesasAbertas(ServidorAtendimento.java:1263)
   at com.mycompany.system.rmi.ServidorAtendimento$$EnhancerByCGLIB$$4e2520b5.CGLIB$getMesasAbertas$15(<generated>)
   at com.mycompany.system.rmi.ServidorAtendimento$$EnhancerByCGLIB$$4e2520b5$$FastClassByCGLIB$$783cf764.invoke(<generated>)
   at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167)
   at com.mycompany.infra.proxy.GenericProxy.intercept(GenericProxy.java:245)
   at com.mycompany.system.rmi.ServidorAtendimento$$EnhancerByCGLIB$$4e2520b5.getMesasAbertas(<generated>)
   at com.mycompany.system.rmi.ServidorAtendimento.abrirMesaAtendimento(ServidorAtendimento.java:751)
   at com.mycompany.system.rmi.ServidorAtendimento$$EnhancerByCGLIB$$4e2520b5.CGLIB$abrirMesaAtendimento$17(<generated>)
   at com.mycompany.system.rmi.ServidorAtendimento$$EnhancerByCGLIB$$4e2520b5$$FastClassByCGLIB$$783cf764.invoke(<generated>)
   at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167)
   at com.mycompany.infra.proxy.GenericProxy.intercept(GenericProxy.java:245)
   at com.mycompany.system.rmi.ServidorAtendimento$$EnhancerByCGLIB$$4e2520b5.abrirMesaAtendimento(<generated>)
   at com.mycompany.system.web.action.AbrirMesaAction.insert(AbrirMesaAction.java:35)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
   at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
   at com.mycompany.system.gui.struts.systemRequestProcessor.processActionPerform(systemRequestProcessor.java:96)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
   at com.mycompany.system.gui.struts.systemRequestProcessor.process(systemRequestProcessor.java:85)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at com.mycompany.infra.persistence.hibernate3.OpenSessionInViewFilter.doFilter(OpenSessionInViewFilter.java:57)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
   at java.lang.Thread.run(Thread.java:534)
StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
java.lang.NullPointerException
   at com.mycompany.system.gui.struts.systemExceptionHandler.execute(systemExceptionHandler.java:48)
   at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:553)
   at com.mycompany.system.gui.struts.systemRequestProcessor.processActionPerform(systemRequestProcessor.java:98)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
   at com.mycompany.system.gui.struts.systemRequestProcessor.process(systemRequestProcessor.java:85)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at com.mycompany.infra.persistence.hibernate3.OpenSessionInViewFilter.doFilter(OpenSessionInViewFilter.java:57)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
   at java.lang.Thread.run(Thread.java:534)

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 9:44 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Marcos Silva Pereira wrote:
Section 5.1.11 from the manual says that "lazy="false" specifies that the association will always be eagerly fetched.

This only applies when loading the object using Session.get/load, or when following an association to the object. It doesn't apply to HQL or Critieria, they have their own ways of specifying whether or not an association should be proxied or fetched eagerly.

From the trace you provided, I'm going to guess that Atendente.getLogin() accesses a member field. Methods in hibernated classes cannot (normally) refer to member fields: the only exception to this is get<field> and set<field>. All other methods must call those get and set methods. So if you currently have code like this:
Code:
public String getLogin() {
  return usario.getLogin();
}
You must change it to this:
Code:
public String getLogin() {
  return getUsario().getLogin();
}

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 11:25 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
tenwit, thank you very much for your answer. Some more doubts and informations about my problem.
tenwit wrote:
This only applies when loading the object using Session.get/load, or when following an association to the object.

I will try to use get/load to retrieve my objects and see its behavior.
tenwit wrote:
It doesn't apply to HQL or Critieria, they have their own ways of specifying whether or not an association should be proxied or fetched eagerly.

Hum, but, using join fecth as I show before must load "usuario" relationship, don't? I think that is the expected behavior, so, I could load a collection of "mesas" eagerly.
tenwit wrote:
From the trace you provided, I'm going to guess that Atendente.getLogin() accesses a member field. Methods in hibernated classes cannot (normally) refer to member fields: the only exception to this is get<field> and set<field>. All other methods must call those get and set methods. So if you currently have code like this:
Code:
public String getLogin() {
  return usario.getLogin();
}
You must change it to this:
Code:
public String getLogin() {
  return getUsario().getLogin();
}

Yeah, I correct it before post question here because it sounds right to me. Due to the fact that hibernate does not use AOP to see any access to fields. :-D

Thanks again.

Kind Regards

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 11:46 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Quote:
Hum, but, using join fecth as I show before must load "usuario" relationship, don't? I think that is the expected behavior, so, I could load a collection of "mesas" eagerly.

Yep, that's right.

I looked at your query again, and I noticed one thing that you might want to fix. Your query will return an Object[3], being {mesa, atendente, usario}. You probably don't want that, seeing as every atendente and usario that the query returns will already be in the appropriate collections of mesa. If you add a "select mesa" at the beginning, you'll avoid all those extra objects.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 1:01 am 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
tenwit wrote:
Quote:
Hum, but, using join fecth as I show before must load "usuario" relationship, don't? I think that is the expected behavior, so, I could load a collection of "mesas" eagerly.

Yep, that's right.

So, what could be wrong with query? It does not retrieve "usario" object properly, it comes null.
tenwit wrote:
I looked at your query again, and I noticed one thing that you might want to fix. Your query will return an Object[3], being {mesa, atendente, usario}. You probably don't want that, seeing as every atendente and usario that the query returns will already be in the appropriate collections of mesa. If you add a "select mesa" at the beginning, you'll avoid all those extra objects.

Hum, I don't think so. My code that executes HQL is:
Code:
Object[] params = { mesaId };
Collections mesas = persistenceManager.find("QueryName", params);
for(Object m : mesas) {
   Mesa mesa = (Mesa)m; // pay attention here
}

If the return was a Object[3], a ClassCastException will be arise. But I will verify it better using hibernate tools, later.

Kind Regards

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 9:36 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I can't see anything else wrong with what you've got. At this point, I'd start debugging. You could be explicit in your many-to-one mapping to Usario, by including a class="Usario" (at the moment, it's inferring that from the name attribute), but I doubt that that will help.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 3:45 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
tenwit wrote:
I can't see anything else wrong with what you've got. At this point, I'd start debugging. You could be explicit in your many-to-one mapping to Usario, by including a class="Usario" (at the moment, it's inferring that from the name attribute), but I doubt that that will help.

I have tried a lot of things:
1. class="Usuario";
2. puts fetch="join" on Atendente and Usuario relationship;
3. puts lazy="proxy";
4. Use join fetch in HQL;
5. Use FetchMode.JOIN with Criteria.

All of these without success. So, I decide to write a complete isolate testing project to see what is happen and, all works fine to this project, but I (and others here) can't see where is the diference between projects. I'm lock in this problem for a few days without success, but I really think that my problems lie on subclasses mapping because others situations where I load objects from this hierarchy have the same problem (come with null values). I decide to put the complete mapping here for someone take a look:
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 default-lazy="false"  schema="Atendimento">
   <class
      name="com.company.project.model.Mesa"
      dynamic-update="false"
      dynamic-insert="false">
      
      <id name="id" column="id" type="long" unsaved-value="-1">
         <generator class="increment"/>
      </id>
      
      <property
         name="data"
         type="date"
         update="true"
         insert="true"
         column="data"/>
      
      <many-to-one
         name="agencia"
         column="id_agencia"
         />
      
      <many-to-one
         name="mesaUnit"
         column="mesa_unit"/>
      
      <many-to-one name="atendente" fetch="join"/>
      
      <property
         name="status"
         type="int"
         update="true"
         insert="true"
         column="status"/>
      
      <property
         name="dataAbertura"
         type="java.util.Date"
         update="true"
         insert="true"
         column="data_abertura"/>
      
      <many-to-one
         name="usuarioAbertura"
         class="com.provider.gfin.user.TBUser"
         cascade="none"
         outer-join="auto"
         update="true"
         insert="true"
         column="usuario_abertura"/>
      
      <property
         name="dataFechamento"
         type="java.util.Date"
         update="true"
         insert="true"
         column="data_fechamento"/>
      
      <many-to-one
         name="usuarioFechamento"
         column="usuario_fechamento"/>
      
      <property
         name="dataInicioStatus"
         type="java.util.Date"
         update="true"
         insert="true"
         column="data_inicio_status"/>
      
      <set name="historicoMesa" lazy="true" inverse="true">
         <key column="id_mesa"/>
         <one-to-many class="com.company.project.model.support.HistoricoStatusMesa"/>
      </set>
      
      <joined-subclass
         name="com.company.project.model.MesaRecepcao"
         table="mesa_recepcao">
         
         <key column="id"/>
         
      </joined-subclass>
      
      <joined-subclass
         name="com.company.project.model.MesaAtendimento"
         table="mesa_atendimento">
         
         <key column="id"/>
         
         <many-to-one
            name="senhaAtual"
            column="senha_atual"/>
         
         <property
            name="numeroAtendimento"
            type="int"
            update="true"
            insert="true"
            column="numero_atendimento"/>
         
      </joined-subclass>
      
   </class>
</hibernate-mapping>

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 default-lazy="false"  schema = "ControleAcesso">

   <class name="com.company.project.accesscontrol.AControlEntity">
      
      <id name="id" unsaved-value="-1">
         <generator class="increment"/>
      </id>
      
      <set name="permissions" lazy="true" batch-size="10">
         <key column="permission_id"/>
         <one-to-many class="com.company.project.accesscontrol.tbfunction.TBFunction"/>
      </set>

      <joined-subclass name="com.company.project.company.Company">
         
         <key column="ID"/>
         
         <property name="codigoDoGrupo" unique="true"/>
         
         <property name="nomeDoGrupo"/>
         
         <property name="nomeDaEmpresa"/>
         
         <property name="nomeFantasia"/>
         
         <property name="realm" unique="true" not-null="true"/>
         
         <property name="pabx"/>
         
         <property name="nire"/>
         
         <property name="atividade"/>
         
         <property name="industria"/>
         
         <property name="cnpj" unique="true"/>
         
         <property name="dataInscricaoCnpj"/>
         
         <property name="idioma"/>
         
         <many-to-one name="endereco" cascade="all"/>
         
         <set name="setores" cascade="all">
            <key column="company_id"/>
            <one-to-many class="com.company.project.company.Setor"/>
         </set>
         
      </joined-subclass>
      
      <joined-subclass name="com.company.project.branch.Branch">
      
         
         <key column="ID"/>
         
         <property name="cnpj"/>
         
         <property name="pracaCompensacao"/>
         
         <property name="idioma" not-null="true"/>
         
         <property name="openingDate"/>
         
         <many-to-one name="address" cascade="all"/>
         
         <property name="name"/>
         
         <property name="sigla"/>
         
         <property name="code">
            <column name="code" unique-key="uk"/>
         </property>
         
         <many-to-one name="diretorPresidente" cascade="all" outer-join="false"/>
         
         <many-to-one name="diretorSecundario" cascade="all" outer-join="false"/>
         
         <many-to-one name="responsavelContabilidade" cascade="all" outer-join="false"/>
         
         <many-to-one name="tipo" not-null="true" column="id_tipo" outer-join="false"/>
         
         <many-to-one name="company" not-null="true" outer-join="false">
            <column name="company" unique-key="uk"/>
         </many-to-one>
         
      </joined-subclass>
      
      <joined-subclass name="com.company.project.jobfunction.JobFunction">
         
         <key column="ID"/>
         
         <property name="code">
            <column name="code" unique-key="uk"/>
         </property>
         
         <property name="name" not-null="true" unique="true"/>

         <property name="description"/>

         <many-to-one name="company" not-null="true">
            <column name="company" unique-key="uk"/>
         </many-to-one>
                           
      </joined-subclass>
            
      <joined-subclass name="com.company.project.user.TBUser">
      
         <key column="ID"/>
         
         <property name="login" not-null="true" unique="true"/>
         
         <property name="password" not-null="true"/>
         
         <property name="registration" not-null="true"/>
         
         <property name="name"/>
         
         <property name="apelido"/>
         
         <property name="nivel" not-null="true"/>

         <property name="idioma"/>
         
         <many-to-one name="branch"/>

         <many-to-one name="jobFunction"/>
         
         <set name="agenciasPermitidas" batch-size="5">
            <key column="TBUser"/>
            <many-to-many class="com.company.project.branch.Branch" />
         </set>
         
      </joined-subclass>
      
   </class>
   
</hibernate-mapping>

Sorry if is so dirty read long mappings. Anyone have some idea about what is wrong?

Kind Regards

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 5:50 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Still no idea. Have you experimented with the <class> element's "lazy" attribute? I am aware of a bug in 3.0.x, that I believe has been fixed in 3.1+, that afflicted classes mapped as lazy="true" (the default) mutable="false", and resulted in null values in objects that looked like they'd been loaded correctly. Perhaps there's another bug in a similar area in 3.1? Try setting lazy="false" on the various class elements, just in case...

Sorry I can't help more.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 10:18 pm 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
I think you'r right on the money there......

tenwit wrote:
I am aware of a bug in 3.0.x, that I believe has been fixed
in 3.1+


I was having exactly the same problem today I tried to use Criteria an HQL
none of the worked to get deeper that one fetch


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 5:09 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
tenwit wrote:
I am aware of a bug in 3.0.x, that I believe has been fixed in 3.1+, that afflicted classes mapped as lazy="true" (the default) mutable="false", and resulted in null values in objects that looked like they'd been loaded correctly.

tenwit , thank you very much. I put lazy="false" in all mappings and now everything works fine. As you say before, this could be a similar bug at Hibernate (3.1.3), not sure about it. Other detail, I remove all default-lazy="true" from my mappings too. I will try do one thing per time and see what is the more correct solution.

Again, really really thanks.

Kind Regards

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 25, 2006 1:16 pm 
Newbie

Joined: Tue May 24, 2005 10:30 am
Posts: 7
Setting default-lazy to false will fetch a lot of data unnecessarily.


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