Tips and Tricks in a world of Mix

Posts tagged ‘Nhibernate’

NHibernate accessing the SP getting errors – NHibernate.Loader.Loader.DoList ?–no solution yet! anyone?



using (ISession Session = NHibernateSessionProvider.GetSession("MYDB"))
using (NHibernate.ITransaction Tran = Session.BeginTransaction(System.Data.IsolationLevel.Serializable))
IQuery query = (IQuery)Session.GetNamedQuery("MYSPNAME").SetResultTransformer(Transformers.AliasToBean(typeof(Sample))); ;
query.SetParameter("p_1", 1);
query.SetParameter("p_2", 12345678);
query.SetDateTime("p_3", null);

IList result = query.List();


Model :

public class Sample : Entity
public virtual int Id { get; set; }
public virtual int SerialNumber { get; set; }




<?xml version=”1.0″ encoding=”utf-8″ ?>
<!– Generated by MoreGen 28-Apr-2008 11:27:28 –>
<hibernate-mapping xmlns=”urn:nhibernate-mapping-2.2″ assembly=”ASSEMBLYNAME”
<class name=”Sample” table=”MYSPNAME” lazy=”true”>
<id name=”Id” column=”ID”>
<generator class=”native” />
<property name=”SerialNumber” column=”serial_number” />
<loader query-ref=”MYSPNAME”/>
<sql-query name=”MYSPNAME” >
<return alias=”MYSPNAME” class=”Sample”>
<return-property name=”SerialNumber” column=”serial_number” />

exec [OLTP_PACK.GET_SAMPLE_LIST]  :p_1 , :p_2 , :p_3



got an advise to try out this post
didn't work either..

Problem Using Stored Procedure with Fluent Nhibernate

    1. Gave the mapping file the extension .hbm.xml
    2. Set the build action to ‘Embedded Resource’
    3. Set the copy-to-output to ‘Copy Always’
    4. Created the Hbm for SP:

<?xml version=1.0encoding=utf-8?>
hibernate-mapping xmlns=urn:nhibernate-mapping-2.2assembly=Infranamespace=Infra.Entities>
<sql-query name=GETMYDATA>
return class=Kav>
return-property column=Kav.MAKAT8name=MAKAT8/>
return-property column=Kav.DESCRIPTIONname=DESCRIPTION/>


5. Created the Entity class :

using System;

namespace Infra.Entities
public class Kav : Entity
public virtual string Makat8 { get; set; }
public virtual string Description { get; set; }

6. Created the Mapping class for the entity:

namespace Infra.Entities.Mapping
public class KavMapping : EntityClassMap<Kav>
public KavMapping()
Id(x => x.Makat8).Column(“MAKAT8”).Length(10);
Map(x => x.Description).Column(“Description”).Length(50);


7. Added the mapping to the FNH configuration (the entities and hbm in the same assembly) :

.Mappings(m =>
} )

I’ve read Ayende’s post on connecting to SP , but I’m failing to connect.

How should I map the Kav so that I could get the list of entities from SP ?

Fluent Nhibernate – fail-safe cleanup (collections) warning


My mapping was in CustomerMutzar :

  HasMany<CustomerMutzarKishur>(x => x.Col_CustomerMutzarKishur)


Class Diagram of my entity model was :

The mistake I’ve got in NHibernate Profiler :

it does the select query :

       left outer join CUSTOMER_MUTZAR_KISHUR col_custom1_
         on customermu0_.CMU_RECID = col_custom1_.CMK_CMU_RECID
       left outer join CUSTOMER_MUTZAR_PRODUCT customermu2_
         on col_custom1_.CMK_CMP_RECID = customermu2_.CMP_RECID
WHERE  customermu0_.CMU_RECID = 450 /* :p0 */


and then I get few problematic statements in profiler :

fail-safe cleanup (collections) : NHibernate.Engine.Loading.CollectionLoadContext<rs=System.Data.OracleClient.OracleDataReader>

On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [1] entries

and a system crash from log  :

StackTrace: NHibernate.PropertyAccessException: Invalid Cast (check your mapping for property type mismatches); setter of Ness.DoarKamuti.Infrastructure.Entities.CustomerMutzar —> System.InvalidCastException: Unable to cast object of type ‘NHibernate.Collection.Generic.PersistentGenericSet`1[Ness.DoarKamuti.Infrastructure.Entities.CustomerMutzarKishur]’ to type ‘System.Collections.Generic.IList`1[Ness.DoarKamuti.Infrastructure.Entities.CustomerMutzarKishur]’.
   at (Object , Object[] , SetterCallback )

The Solution :

I went again to the mapping of the entity and adjusted the relationships :


 HasMany<CustomerMutzarKishur>(x => x.Col_CustomerMutzarKishur).AsBag()

This has resolved the issue for me.


Tag Cloud

%d bloggers like this: