-->
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.  [ 1 post ] 
Author Message
 Post subject: stored procedure with nhibernate - error
PostPosted: Wed Aug 11, 2010 5:08 am 
Newbie

Joined: Tue Aug 10, 2010 8:10 am
Posts: 1
Iam new to nhibernate .
I was just trying to execute an Sp using nhibernate.
I have compiled the solution by making the below contact.cs as embedded resource.

But its giving me the error could not execute query
[ exec [Nhibernate-Test-Sp] ]
[SQL: exec [Nhibernate-Test-Sp]]


Please help me out



Code to execute the query

public List<Contact> GetContacts()
{
ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();
NHibernate.ISession session = sessionFactory.OpenSession();
IQuery query = session.GetNamedQuery("GetContacts");
return query.List<Contact>() as List<Contact>;

}



This is my Contact.cs class

public class Contact
{
private int _contactId;
private string _firstName;
private string _lastName;
private string _email;
private string _telephone;
private static int id = 10;

public Contact(int contactid, string firstname, string lastname, string email, string telephone)
{
_contactId = contactid;
_firstName = firstname;
_lastName=lastname;
_email = email;
_telephone = telephone;
}

public Contact()
{ }

public virtual int ContactId
{
get { return _contactId; }
set { _contactId = value; }
}

public virtual string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}

public virtual string LastName
{
get { return _lastName; }
set { _lastName = value; }
}

public virtual string Email
{
get { return _email; }
set { _email = value; }
}

public virtual string Telephone
{
get { return _telephone; }
set { _telephone = value; }
}



}

Mapping Xml for the class

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<sql-query name="GetContacts">
<return-scalar column="ContactId" type="Int" />
<return-scalar column="FirstName" type="String" />
<return-scalar column="LastName" type="String" />
<return-scalar column="Email" type="String" />
<return-scalar column="Telephone" type="String" />
exec [Nhibernate-Test-Sp]
</sql-query>
</hibernate-mapping>


This is my procedure


CREATE PROCEDURE [DEV\tcs-nby].[Nhibernate-Test-Sp]
AS
BEGIN
SET NOCOUNT ON;
SELECT Contact_id,[first_name],last_name,email,telephone
FROM[tbl_contact]

END
GO




Web.config Details

<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<reflection-optimizer use="false" />
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider </property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="connection.connection_string">Server=VICDEVD;database=DEV121;Integrated Security=SSPI;</property>
<property name="show_sql">false</property>
<property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver </property>
<property name="connection.isolation">ReadCommitted</property>
<mapping assembly="Contacts" />

</session-factory>
</hibernate-configuration>

Thanks

Renjith


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.