-->
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.  [ 4 posts ] 
Author Message
 Post subject: Strange bug (behaviour) with proxies
PostPosted: Tue Jun 21, 2005 12:01 pm 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
I was finding this strange issue while using proxies.

I have set the proxy attributes on some classes to enhance performance. The methods seems to work fine except when the method is fired from a new thread. I don't really believe the thread is the issue here, but basically what I found strange is that the query seems to be fireing correctly but instead of returning a normal object, I'm getting a Proxy.

I tried using NHibernate.Util.Initialize method but doesn't seem to be working either.

I'm sending you guys the hbm files to view them

class Recepcion
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
   xmlns="urn:nhibernate-mapping-2.0" 
   namespace="SAFJP.SICI.Model.Carteras"
   assembly="SAFJP.SICI.Model.Carteras"
   default-access="field">
   <import class="SAFJP.SICI.Model.Carteras.ITest" />

    <class
      name="Recepcion"
      table="T_Recepcion">
           
      <id
         name="mId"
         column="recepcion_ID"
         type="Int32"
         unsaved-value="-1">
         <generator class="native" />
      </id>
      
      <property
         name="Dia"
         column="D_recepcion"
         type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"
         access="property"
      />
      
      <property
         name="Responsable"
         column="responsable"
         type="String"
         length="4000"
         access="property"
      />
      
      <property
         name="Comentarios"
         column="comentarios"
         type="String"
         length="4000"
         access="property"
      />
      
      
      <many-to-one
         name="mInformeDiario"
         column="informeDiario_FK"
         class="InformeDiario"
         not-null="true"
      />
      
      
      <many-to-one
         name="mID11"
         column="ID11"
         class="SAFJP.SICI.Model.Carteras.FormularioID.FormularioID11"
         cascade="all-delete-orphan"
         outer-join="false"
      />
   </class>
</hibernate-mapping>


class FormularioID
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
   xmlns="urn:nhibernate-mapping-2.0" 
   namespace="SAFJP.SICI.Model.Carteras.FormularioID"
   assembly="SAFJP.SICI.Model.Carteras"
   default-access="field">

    <class
   name="Formulario"
        table="T_Formulario"
        lazy="true">
           
        <id
      name="mId"
      column="Formulario_ID"
      type="Int32"
      unsaved-value="-1">
      <generator class="native"/>
      </id>
      
      <discriminator
         column="Tipo_Formulario"
         type="string"
         length="3"
      />
      
      <bag
         name="mEntradas"
         table="T_Entrada_Formulario"
         cascade="all"
         lazy="true"
         >
         <key column="Formulario_ID" />
         <one-to-many class="EntradaFormulario"
         />
      </bag>
      <!-- ================================   -->
      <!-- Subclass FormularioID11         -->
      <!-- ================================   -->
      <subclass
         name="FormularioID11"
         discriminator-value="11"
         lazy="true"
      />
   </class>
</hibernate-mapping>


class EntradaFormulario
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
   xmlns="urn:nhibernate-mapping-2.0" 
   namespace="SAFJP.SICI.Model.Carteras.FormularioID"
   assembly="SAFJP.SICI.Model.Carteras"
   default-access="field">

    <class
   name="EntradaFormulario"
        table="T_Entrada_Formulario">
           
        <id
      name="mId"
      column="Entrada_ID"
      type="Int32"
      unsaved-value="-1">
      <generator class="native"/>
   </id>
      <!-- ================================   -->
      <!-- Subclass EntradaFormularioID11      -->
      <!-- ================================   -->
      <joined-subclass
         name="EntradaFormularioID11"
         table="T_Entrada_Formulario_ID11">
         <key column="Entrada_ID"/>
         <property
            name="mCodigoCuenta"
            column="Codigo_Cuenta"
            type="string"
            length="9"
         />
         <property
            name="mNumeroCuotas"
            column="A_Cuotas"
            type="Nullables.NHibernate.NullableDecimalType, Nullables.NHibernate"
         />
         <property
            name="mImporte"
            column="A_Importe"
            type="Nullables.NHibernate.NullableDecimalType, Nullables.NHibernate"
         />
      </joined-subclass>
   </class>
</hibernate-mapping>


In my query I bascally want to retrieve the Formulario given a Recepcion ID. Here's the query (it's in VB.NET, but it kinda easy to understan). In this code I added the Initialize method in because in some ocassions I get a proxy object.

Code:
    Private Function FPorIdRecepcion(ByVal idRec As Integer, ByVal prop As String) As Object
        Dim session As ISession = NHContext.Current.NHibernateSession

        Dim q As IQuery = session.CreateQuery("select rec." + prop + " from Recepcion rec where rec.mId = :idRec")
        q.SetInt32("idRec", idRec)

        Return q.UniqueResult()
    End Function


Any ideas??


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 22, 2005 5:45 pm 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
Please I need help! I haven't been able to locate the problem


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 6:06 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
As far as I understand, you are retrieving a many-to-one property of some object? Try changing the query to something like this:
Code:
select prop from Recepcion rec left join fetch rec.<someproperty> prop where ...


i.e. use a "join fetch" and an alias (but maybe it will work without the alias, too).

By the way, NHibernateUtil.Initialize definitely should work. I wonder why it doesn't.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 5:58 pm 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
I feel so stupid...I found what it was and learned a few new things.

The first one was that I was actulally calling a private method of the proxied object, so the proxy had no chance to really initialize itself.

the second one is the way proxies work: I thought that once you initialized the proxy the reference was replaced with the real object (big mistake).

This was not a problem in my first case because the first time the objects where in cache already so when I requested them the second time there was no need to return a proxy (nice going hibernate!!)

Anyways, hope my conclusions serves someone:

While using proxies try to avoid using members, only properties. And make sure those properties are declared virtual


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