-->
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.  [ 7 posts ] 
Author Message
 Post subject: problem with lazy loading and inheritance
PostPosted: Tue Sep 27, 2005 6:09 am 
Newbie

Joined: Mon May 16, 2005 5:58 am
Posts: 11
Location: Galicia, Spain
I have the following scene: class "Person", and classes "Student" and "Teacher" inherit from "Person"

If I set lazy=true in the hbm definition, a collection of "Person" generates a list of proxy objects of type CProxyTypePerson_INHibernateProxy_ISerializable2

The problem:
"Student" and "Teacher" inherit from "Person" and all objects of "Person" are type of "Student" or "Teacher"
My collection are type of "CProxyTypePerson_INHibernateProxy_ISerializable2"
!!! "Student" and "Teacher" don


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 7:07 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Student and Teacher do not inherit from their proxy types, but the reverse is true, so if _person is "StudentProxy", then "_person is Student" should be true. What will not work is the exact type check: _person.GetType() == typeof(Person).

Besides, Find("FROM Person") should return real objects, as far as I can understand. I guess the code you showed here is not the actual code that is executed, and you may have a bug in the actual code somewhere. But please correct me if I'm wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 8:07 am 
Newbie

Joined: Mon May 16, 2005 5:58 am
Posts: 11
Location: Galicia, Spain
yes, that code tried to be a sample ;D, sorry
I have a custom Find, but the scene could be recreate with one-to-many relation with lazy=true.

I you want I could try post the real code, but we have a lot of self-code


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 9:16 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Quote:
I you want I could try post the real code, but we have a lot of self-code

Well, try it :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 10:37 am 
Newbie

Joined: Mon May 16, 2005 5:58 am
Posts: 11
Location: Galicia, Spain
ok, this is the code:

Code:
   
        public IList Find(string query)
        {
            try
            {
                IEnumerable enumerable = Session.Enumerable(query);
                Collection collection = new Collection(enumerable);
                return collection;
            }
            catch(Exception e)
            {
                CloseAndReOpen();
                throw e;
            }
        }


Hbm file:
Code:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-access="field">
  <class name="MyProject.BOL.MArticulo, MyProject.BOL" table="MArticulo" persister="MyProject.DAL.CustomPersister, MyProject.DAL" lazy="false">
    <jcs-cache usage="read-write" />
    <id name="Id" column="Id" type="Guid" unsaved-value="{00000000-0000-0000-0000-000000000000}">
      <generator class="guid" />
    </id>
    <version name="version" column="version" type="Int32" />
    <property name="codigo" column="codigo" type="String" length="50" />
    <property name="descripcion" column="descripcion" type="String" length="150" />
    <property name="unidadMedidaPeso" column="unidadMedidaPeso" type="String" length="50" />
    <property name="pesoStock" column="pesoStock" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
    <property name="cantidadStock" column="cantidadStock" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
    <set name="lineasEntrega_nh" lazy="true" cascade="save-update">
      <key>
        <column name="IdMArticulo" />
      </key>
      <one-to-many class="MyProject.BOL.LineaEntrega, MyProject.BOL" />
    </set>
    <set name="previsionesRecepcion_nh" lazy="true" cascade="all">
      <key>
        <column name="IdMArticulo" />
      </key>
      <one-to-many class="MyProject.BOL.PrevisionRecepcion, MyProject.BOL" />
    </set>
    <property name="userc" column="userc" type="String" length="80" />
    <property name="hostc" column="hostc" type="String" length="80" />
    <property name="datec" column="datec" type="DateTime" />
    <property name="usera" column="usera" type="String" length="80" />
    <property name="hosta" column="hosta" type="String" length="80" />
    <property name="datea" column="datea" type="DateTime" />
    <set name="proveedores_nh" table="proveedores_nh_mArticulos_nh" lazy="true" inverse="true" cascade="save-update">
      <key>
        <column name="idMArticulos_nh" />
      </key>
      <many-to-many class="MyProject.BOL.Proveedor, MyProject.BOL" column="idProveedores_nh" />
    </set>
    <joined-subclass name="MyProject.BOL.MConsumible, MyProject.BOL" table="MConsumible" lazy="false">
      <key column="Id" />
      <joined-subclass name="MyProject.BOL.MBobina, MyProject.BOL" table="MBobina" lazy="true">
        <key column="Id" />
        <property name="gramaje" column="gramaje" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="hornos" column="hornos" type="Boolean" />
        <property name="caras" column="caras" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <property name="ancho" column="ancho" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="diametro" column="diametro" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <many-to-one name="mTipoPapel" column="idMTipoPapel" class="MyProject.BOL.MTipoPapel, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="colorPapel" column="idColorPapel" class="MyProject.BOL.ColorPapel, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="acabadoPapel" column="idAcabadoPapel" class="MyProject.BOL.AcabadoPapel, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="tipoPastaPapel" column="idTipoPastaPapel" class="MyProject.BOL.TipoPastaPapel, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="blancuraPapel" column="idBlancuraPapel" class="MyProject.BOL.BlancuraPapel, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="clasePapel" column="idClasePapel" class="MyProject.BOL.ClasePapel, MyProject.BOL" cascade="save-update" not-null="false" />
      </joined-subclass>
      <joined-subclass name="MyProject.BOL.MCajaCarton, MyProject.BOL" table="MCajaCarton" lazy="true">
        <key column="Id" />
        <property name="ancho" column="ancho" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="alto" column="alto" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="largo" column="largo" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="color" column="color" type="String" length="50" />
        <property name="impresa" column="impresa" type="Boolean" />
        <property name="tintas" column="tintas" type="String" length="50" />
        <property name="canales" column="canales" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <property name="nCaras" column="nCaras" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <many-to-one name="tipoCaja" column="idTipoCaja" class="MyProject.BOL.TipoCaja, MyProject.BOL" cascade="save-update" not-null="false" />
      </joined-subclass>
      <joined-subclass name="MyProject.BOL.MCola, MyProject.BOL" table="MCola" lazy="true">
        <key column="Id" />
      </joined-subclass>
      <joined-subclass name="MyProject.BOL.MContenedorSoporte, MyProject.BOL" table="MContenedorSoporte" lazy="true">
        <key column="Id" />
        <property name="ancho" column="ancho" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="largo" column="largo" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="alto" column="alto" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
      </joined-subclass>
      <joined-subclass name="MyProject.BOL.MHoja, MyProject.BOL" table="MHoja" lazy="true">
        <key column="Id" />
        <property name="gramaje" column="gramaje" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="hornos" column="hornos" type="Boolean" />
        <property name="caras" column="caras" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <property name="ancho" column="ancho" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="largo" column="largo" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <many-to-one name="mTipoPapel" column="idMTipoPapel" class="MyProject.BOL.MTipoPapel, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="colorPapel" column="idColorPapel" class="MyProject.BOL.ColorPapel, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="acabadoPapel" column="idAcabadoPapel" class="MyProject.BOL.AcabadoPapel, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="formato" column="idFormato" class="MyProject.BOL.Formato, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="tipoPastaPapel" column="idTipoPastaPapel" class="MyProject.BOL.TipoPastaPapel, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="blancuraPapel" column="idBlancuraPapel" class="MyProject.BOL.BlancuraPapel, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="fibras" column="idFibras" class="MyProject.BOL.Fibras, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="clasePapel" column="idClasePapel" class="MyProject.BOL.ClasePapel, MyProject.BOL" cascade="save-update" not-null="false" />
      </joined-subclass>
      <joined-subclass name="MyProject.BOL.MPaletSoporte, MyProject.BOL" table="MPaletSoporte" lazy="true">
        <key column="Id" />
        <property name="ancho" column="ancho" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="largo" column="largo" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="alto" column="alto" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="peso" column="peso" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <many-to-one name="tipoPalet" column="idTipoPalet" class="MyProject.BOL.TipoPalet, MyProject.BOL" cascade="save-update" not-null="false" />
      </joined-subclass>
      <joined-subclass name="MyProject.BOL.MPlancha, MyProject.BOL" table="MPlancha" lazy="true">
        <key column="Id" />
        <property name="ancho" column="ancho" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <property name="largo" column="largo" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <property name="espesor" column="espesor" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="material" column="material" type="String" length="50" />
      </joined-subclass>
      <joined-subclass name="MyProject.BOL.MPolietileno, MyProject.BOL" table="MPolietileno" lazy="true">
        <key column="Id" />
        <property name="espesor" column="espesor" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="gramaje" column="gramaje" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="ancho" column="ancho" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="diametro" column="diametro" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="impreso" column="impreso" type="Boolean" />
        <many-to-one name="tipoPolietileno" column="idTipoPolietileno" class="MyProject.BOL.TipoPolietileno, MyProject.BOL" cascade="save-update" not-null="false" />
      </joined-subclass>
      <joined-subclass name="MyProject.BOL.MTinta, MyProject.BOL" table="MTinta" lazy="true">
        <key column="Id" />
        <property name="tipoImpresion" column="tipoImpresion" type="String" length="50" />
        <property name="horno" column="horno" type="Boolean" />
        <many-to-one name="color" column="idColor" class="MyProject.BOL.Color, MyProject.BOL" cascade="save-update" not-null="false" />
      </joined-subclass>
    </joined-subclass>
    <joined-subclass name="MyProject.BOL.TProducto, MyProject.BOL" table="TProducto" lazy="false">
      <key column="Id" />
      <property name="pesoUnitario" column="pesoUnitario" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
      <property name="cantidadProducida" column="cantidadProducida" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
      <property name="cantidadPrevista" column="cantidadPrevista" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
      <many-to-one name="mProducto" column="idMProducto" class="MyProject.BOL.MProducto, MyProject.BOL" cascade="save-update" not-null="false" />
      <many-to-one name="revision" column="idRevision" class="MyProject.BOL.Revision, MyProject.BOL" cascade="save-update" not-null="false" />
      <set name="cantidadesEntrada_nh" lazy="true" inverse="true" cascade="all-delete-orphan">
        <key>
          <column name="idTProductoEntrada" />
        </key>
        <one-to-many class="MyProject.BOL.CantidadEntrada, MyProject.BOL" />
      </set>
      <set name="cantidadesSalida_nh" lazy="true" inverse="true" cascade="all-delete-orphan">
        <key>
          <column name="idTProductoSalida" />
        </key>
        <one-to-many class="MyProject.BOL.CantidadSalida, MyProject.BOL" />
      </set>
      <joined-subclass name="MyProject.BOL.TEmbalaje, MyProject.BOL" table="TEmbalaje" lazy="false">
        <key column="Id" />
        <property name="grosorPlastico" column="grosorPlastico" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="nflejesXZ" column="nflejesXZ" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <property name="nflejesYZ" column="nflejesYZ" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <property name="nflejesXY" column="nflejesXY" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <property name="ancho" column="ancho" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="largo" column="largo" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="alto" column="alto" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <many-to-one name="tipoFlejado" column="idTipoFlejado" class="MyProject.BOL.TipoFlejado, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="tipoPlastico" column="idTipoPlastico" class="MyProject.BOL.TipoPlastico, MyProject.BOL" cascade="save-update" not-null="false" />
        <joined-subclass name="MyProject.BOL.TCaja, MyProject.BOL" table="TCaja" lazy="true">
          <key column="Id" />
          <many-to-one name="mCajaCarton" column="idMCajaCarton" class="MyProject.BOL.MCajaCarton, MyProject.BOL" cascade="save-update" not-null="false" />
          <set name="tPosCajas_nh" lazy="true" inverse="true" cascade="save-update">
            <key>
              <column name="idTCaja" />
            </key>
            <one-to-many class="MyProject.BOL.TPosCaja, MyProject.BOL" />
          </set>
        </joined-subclass>
        <joined-subclass name="MyProject.BOL.TContenedor, MyProject.BOL" table="TContenedor" lazy="true">
          <key column="Id" />
          <many-to-one name="mContenedorSoporte" column="idMContenedorSoporte" class="MyProject.BOL.MContenedorSoporte, MyProject.BOL" cascade="save-update" not-null="false" />
          <set name="tPosContenedores_nh" lazy="true" inverse="true" cascade="all-delete-orphan">
            <key>
              <column name="idTContenedor" />
            </key>
            <one-to-many class="MyProject.BOL.TPosContenedor, MyProject.BOL" />
          </set>
        </joined-subclass>
        <joined-subclass name="MyProject.BOL.TEncartado, MyProject.BOL" table="TEncartado" lazy="true">
          <key column="Id" />
          <many-to-one name="tEjemplar" column="idTEjemplar" class="MyProject.BOL.TEjemplar, MyProject.BOL" cascade="save-update" not-null="false" />
          <set name="tPosEncartados_nh" lazy="true" inverse="true" cascade="all-delete-orphan">
            <key>
              <column name="idTEncartado" />
            </key>
            <one-to-many class="MyProject.BOL.TPosEncartado, MyProject.BOL" />
          </set>
        </joined-subclass>
        <joined-subclass name="MyProject.BOL.TPalet, MyProject.BOL" table="TPalet" lazy="true">
          <key column="Id" />
          <property name="boinas" column="boinas" type="Boolean" />
          <property name="cartonIntermedio" column="cartonIntermedio" type="Boolean" />
          <property name="tapas" column="tapas" type="Boolean" />
          <property name="tipoTapas" column="tipoTapas" type="String" length="50" />
          <property name="nVueltas" column="nVueltas" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
          <property name="numUnidadesBase" column="numUnidadesBase" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
          <property name="numEjemplaresUnidad" column="numEjemplaresUnidad" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
          <property name="numAlturas" column="numAlturas" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
          <many-to-one name="mPaletSoporteCliente" column="idMPaletSoporteCliente" class="MyProject.BOL.MPaletSoporte, MyProject.BOL" cascade="save-update" not-null="false" />
          <set name="tPosPalets_nh" lazy="true" inverse="true" cascade="all-delete-orphan">
            <key>
              <column name="idTPalet" />
            </key>
            <one-to-many class="MyProject.BOL.TPosPalet, MyProject.BOL" />
          </set>
        </joined-subclass>
        <joined-subclass name="MyProject.BOL.TPaquete, MyProject.BOL" table="TPaquete" lazy="true">
          <key column="Id" />
          <set name="tPosPaquetes_nh" lazy="true" inverse="true" cascade="all-delete-orphan">
            <key>
              <column name="idTPaquete" />
            </key>
            <one-to-many class="MyProject.BOL.TPosPaquete, MyProject.BOL" />
          </set>
        </joined-subclass>
      </joined-subclass>
      <joined-subclass name="MyProject.BOL.TProductoEncuadernable, MyProject.BOL" table="TProductoEncuadernable" lazy="false">
        <key column="Id" />
        <property name="sangrePagina" column="sangrePagina" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="fresaPagina" column="fresaPagina" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="anchoNecesarioPagina" column="anchoNecesarioPagina" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="gramaje" column="gramaje" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="ordenEnSeccion" column="ordenEnSeccion" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <many-to-one name="formato" column="idFormato" class="MyProject.BOL.Formato, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="tipoPlegado" column="idTipoPlegado" class="MyProject.BOL.TipoPlegado, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="tipoTrepado" column="idTipoTrepado" class="MyProject.BOL.TipoTrepado, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="tipoTroquelado" column="idTipoTroquelado" class="MyProject.BOL.TipoTroquelado, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="tipoTinta" column="idTipoTinta" class="MyProject.BOL.TipoTinta, MyProject.BOL" cascade="save-update" not-null="false" />
        <set name="tLibros_nh" table="tProductosEncuadernables_nh_tLibros_nh" lazy="true" inverse="true" cascade="save-update">
          <key>
            <column name="idTProductosEncuadernables_nh" />
          </key>
          <many-to-many class="MyProject.BOL.TLibro, MyProject.BOL" column="idTLibros_nh" />
        </set>
        <joined-subclass name="MyProject.BOL.TCubierta, MyProject.BOL" table="TCubierta" lazy="true">
          <key column="Id" />
          <property name="lomoPreimpresion" column="lomoPreimpresion" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
          <many-to-one name="tipoBarnizCara" column="idTipoBarnizCara" class="MyProject.BOL.TipoBarniz, MyProject.BOL" cascade="save-update" not-null="false" />
          <many-to-one name="tipoBarnizRetira" column="idTipoBarnizRetira" class="MyProject.BOL.TipoBarniz, MyProject.BOL" cascade="save-update" not-null="false" />
          <many-to-one name="acabadoCubierta" column="idAcabadoCubierta" class="MyProject.BOL.AcabadoCubierta, MyProject.BOL" cascade="save-update" not-null="false" />
          <many-to-one name="formatoSolapaDelantera" column="idFormatoSolapaDelantera" class="MyProject.BOL.Formato, MyProject.BOL" cascade="save-update" not-null="false" />
          <many-to-one name="formatoSolapaTrasera" column="idFormatoSolapaTrasera" class="MyProject.BOL.Formato, MyProject.BOL" cascade="save-update" not-null="false" />
        </joined-subclass>
        <joined-subclass name="MyProject.BOL.TEncarte, MyProject.BOL" table="TEncarte" lazy="true">
          <key column="Id" />
          <property name="solapa" column="solapa" type="Boolean" />
          <many-to-one name="tipoBarnizCara" column="idTipoBarnizCara" class="MyProject.BOL.TipoBarniz, MyProject.BOL" cascade="save-update" not-null="false" />
          <many-to-one name="tipoBarnizRetira" column="idTipoBarnizRetira" class="MyProject.BOL.TipoBarniz, MyProject.BOL" cascade="save-update" not-null="false" />
          <many-to-one name="formatoSolapa" column="idFormatoSolapa" class="MyProject.BOL.Formato, MyProject.BOL" cascade="save-update" not-null="false" />
        </joined-subclass>
        <joined-subclass name="MyProject.BOL.TPliego, MyProject.BOL" table="TPliego" lazy="true">
          <key column="Id" />
          <property name="nPliego" column="nPliego" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
          <many-to-one name="tipoDePlegado" column="idTipoDePlegado" class="MyProject.BOL.TipoPlegado, MyProject.BOL" cascade="save-update" not-null="false" />
          <many-to-one name="formatoEjemplar" column="idFormatoEjemplar" class="MyProject.BOL.Formato, MyProject.BOL" cascade="save-update" not-null="false" />
        </joined-subclass>
      </joined-subclass>
      <joined-subclass name="MyProject.BOL.TEjemplar, MyProject.BOL" table="TEjemplar" lazy="false">
        <key column="Id" />
        <property name="titulo" column="titulo" type="String" length="50" />
        <property name="tiradaTotal" column="tiradaTotal" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="fechaIniEntregas" column="fechaIniEntregas" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
        <property name="fechaFinEntregas" column="fechaFinEntregas" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
        <property name="pieImprenta" column="pieImprenta" type="String" length="50" />
        <property name="depositoLegal" column="depositoLegal" type="String" length="50" />
        <property name="muestra" column="muestra" type="Boolean" />
        <property name="fechaTopeEntregaMuestras" column="fechaTopeEntregaMuestras" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
        <property name="nMuestrasEmbalaje" column="nMuestrasEmbalaje" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <property name="pesoTeorico" column="pesoTeorico" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="suministradoCliente" column="suministradoCliente" type="Boolean" />
        <property name="ancho" column="ancho" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="largo" column="largo" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <many-to-one name="tipoMuestras" column="idTipoMuestras" class="MyProject.BOL.TipoMuestras, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="tipoProducto" column="idTipoProducto" class="MyProject.BOL.TipoProducto, MyProject.BOL" cascade="save-update" not-null="false" />
        <set name="tEncartados_nh" lazy="true" inverse="true" cascade="save-update">
          <key>
            <column name="idTEjemplar" />
          </key>
          <one-to-many class="MyProject.BOL.TEncartado, MyProject.BOL" />
        </set>
        <joined-subclass name="MyProject.BOL.TLibro, MyProject.BOL" table="TLibro" lazy="false">
          <key column="Id" />
          <property name="guardas" column="guardas" type="Boolean" />
          <property name="tapaDura" column="tapaDura" type="Boolean" />
          <property name="lomoEstimado" column="lomoEstimado" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
          <set name="tProductosEncuadernables_nh" table="tProductosEncuadernables_nh_tLibros_nh" lazy="true" inverse="false" cascade="save-update">
            <key>
              <column name="idTLibros_nh" />
            </key>
            <many-to-many class="MyProject.BOL.TProductoEncuadernable, MyProject.BOL" column="idTProductosEncuadernables_nh" />
          </set>
          <set name="secciones_nh" lazy="true" inverse="true" cascade="all-delete-orphan">
            <key>
              <column name="idTLibro" />
            </key>
            <one-to-many class="MyProject.BOL.Seccion, MyProject.BOL" />
          </set>
          <joined-subclass name="MyProject.BOL.TSuplemento, MyProject.BOL" table="TSuplemento" lazy="true">
            <key column="Id" />
          </joined-subclass>
        </joined-subclass>
      </joined-subclass>
      <joined-subclass name="MyProject.BOL.TFichero, MyProject.BOL" table="TFichero" lazy="true">
        <key column="Id" />
        <property name="tamanho" column="tamanho" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="nPaginas" column="nPaginas" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <property name="cMYK" column="cMYK" type="Boolean" />
        <property name="fechaRecepcion" column="fechaRecepcion" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
        <property name="fechaRevision" column="fechaRevision" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
        <property name="nRevision" column="nRevision" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <many-to-one name="resolucionFichero" column="idResolucionFichero" class="MyProject.BOL.ResolucionFichero, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="soporte" column="idSoporte" class="MyProject.BOL.SoporteFichero, MyProject.BOL" cascade="save-update" not-null="false" />
      </joined-subclass>
      <joined-subclass name="MyProject.BOL.THojaImpresa, MyProject.BOL" table="THojaImpresa" lazy="true">
        <key column="Id" />
        <property name="gramaje" column="gramaje" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <many-to-one name="tipoBarnizCara" column="idTipoBarnizCara" class="MyProject.BOL.TipoBarniz, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="tipoBarnizRetira" column="idTipoBarnizRetira" class="MyProject.BOL.TipoBarniz, MyProject.BOL" cascade="save-update" not-null="false" />
        <many-to-one name="formato" column="idFormato" class="MyProject.BOL.Formato, MyProject.BOL" cascade="save-update" not-null="false" />
      </joined-subclass>
      <joined-subclass name="MyProject.BOL.TPlancha, MyProject.BOL" table="TPlancha" lazy="true">
        <key column="Id" />
        <property name="ancho" column="ancho" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="largo" column="largo" type="Nullables.NHibernate.NullableDoubleType, Nullables.NHibernate" />
        <property name="resolucion" column="resolucion" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <property name="lineatura" column="lineatura" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <property name="angulacion" column="angulacion" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" />
        <property name="decoraciones" column="decoraciones" type="Boolean" />
        <property name="corondeles" column="corondeles" type="Boolean" />
        <property name="pPF" column="pPF" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
      </joined-subclass>
    </joined-subclass>
  </class>
</hibernate-mapping>



and I have the problem in the following part of code:



Code:

         string consulta = "from MConsumible m ";
         MyProject.Collections.Set lista = new MyProject.Collections.Set();

         foreach(MConsumible _mconsumible in DAL.DB.CurrentSession().Find(consulta))
         {

            if (((_mconsumible is MBobina) && (this.cbConsumiblebobinas.Checked ))
               || ((_mconsumible is MHoja) && (this.cbConsumibleHojas.Checked ))
               || ((_mconsumible is MPlancha) && (this.cbConsumiblePlanchas.Checked ))
               || ((_mconsumible is MTinta) && (this.cbConsumibleTintas.Checked ))
               || ((_mconsumible is MPolietileno) && (this.cbConsumiblePolietileno.Checked ))
               || ((_mconsumible is BOL.MCajaCarton) && (this.cbConsumibleCajas.Checked ))
               || ((_mconsumible is MCola) && (this.cbConsumibleColas.Checked ))
               || ((_mconsumible is BOL.MContenedorSoporte) && (this.cbConsumibleSopContenedor.Checked ))
               || ((_mconsumible is MPaletSoporte) && (this.cbConsumibleSopPalet.Checked )))
               lista.Add(_mconsumible);
         }


when lazy=true, lista is empty, but when lazy = false, the collection lista has data

In my class definition I have a custom persister that fill the public collections when they are created. Maybe, I have an error in this method and for that reason i do not create the objects of the collection with the correct type.

I am going to try to create a similar structure, but without the wrappers and without my custom methods, and then I


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 2:14 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, now the problem is clear. You use session.Enumerable which only loads entities lazily, so you get back a list of proxies. Since the exact type of each object is unknown, the proxies you get are all proxies for MConsumible. When the object is actually loaded later, the proxy will be changed (narrowed down) to match the actual type of the object. So you really need to change session.Enumerable to session.Find or some other equivalent, to load a list of initialized objects.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 6:07 am 
Newbie

Joined: Mon May 16, 2005 5:58 am
Posts: 11
Location: Galicia, Spain
ok, thanks sergey, I'll try it


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