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??