Tips and Tricks in a world of Mix

Posts tagged ‘SP’

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

http://stackoverflow.com/questions/6696389/nhibernate-accessing-the-sp-getting-errors-nhibernate-loader-loader-dolist

 

BL:

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 :

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

}

 

Mapping:

<?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”
namespace=”ASSEMBLYNAME.Entities”>
<class name=”Sample” table=”MYSPNAME” lazy=”true”>
<id name=”Id” column=”ID”>
<generator class=”native” />
</id>
<property name=”SerialNumber” column=”serial_number” />
<loader query-ref=”MYSPNAME”/>
</class>
<sql-query name=”MYSPNAME” >
<return alias=”MYSPNAME” class=”Sample”>
<return-property name=”SerialNumber” column=”serial_number” />
</return>

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

</sql-query>
</hibernate-mapping>

 

got an advise to try out this post http://devio.wordpress.com/2010/04/21/oracle-stored-procedures-with-nhibernate/
didn't work either..
Advertisements

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/>
</
return>
exec  GETMYDATA  :P_PARAM1 , :P_PARAM2 , :MY_CURSOR
</sql-query>

</hibernate-mapping>

5. Created the Entity class :

using System;

namespace Infra.Entities
{
[Serializable]
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()
{
Table(“kav_tkufa”);
ReadOnly();
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 =>
{
m.FluentMappings.AddFromAssemblyOf<KavMapping>();
m.HbmMappings.AddFromAssemblyOf<KavMapping>();
m.MergeMappings();
} )

I’ve read Ayende’s post http://ayende.com/blog/1692/using-nhibernate-with-stored-procedures 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 ?

Tag Cloud

%d bloggers like this: