-->
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: how to call stored procedure in nhibernate
PostPosted: Thu May 08, 2008 11:16 am 
Newbie

Joined: Sun Jan 27, 2008 4:26 pm
Posts: 18
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
1.2.1
Mapping documents:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace LookupsApp.Model
{
public class Users
{
private int userIDField;
private int contactIDField;
private string userNameField;
private string passWordField;
private int pINField;
private string designationField;
private int numberOfLogonsField;
private int failedLoginsField;
private DateTime? lastFailedLoginField;
private DateTime? lastLogonField;
private DateTime? firstCreatedField;
private DateTime? modifiedDateField;
private int userTypeIDField;
private int statusIDField;
private bool permitRestrictedContentField;
private string notesField;

public Users()
{
}

public virtual int UserID
{
get
{
return this.userIDField;
}
set
{
this.userIDField = value;
}
}
public virtual int ContactID
{
get
{
return this.contactIDField;
}
set
{
this.contactIDField = value;
}
}
public virtual string UserName
{
get
{
return this.userNameField;
}
set
{
this.userNameField = value;
}

}
public virtual string Password
{
get
{
return this.passWordField;
}
set
{
this.passWordField = value;
}
}
public virtual int PIN
{
get
{
return this.pINField;
}
set
{
this.pINField = value;
}
}
public virtual string Designation
{
get
{
return this.designationField;
}
set
{
this.designationField = value;
}
}
public virtual int NumberOfLogons
{
get
{
return this.numberOfLogonsField;
}
set
{
this.numberOfLogonsField = value;
}
}
public virtual int FailedLogins
{
get
{
return this.failedLoginsField;
}
set
{
this.failedLoginsField = value;
}
}
public virtual DateTime? LastFailedLogin
{
get
{
return this.lastFailedLoginField;
}
set
{
this.lastFailedLoginField = value;
}
}
public virtual DateTime? LastLogon
{
get
{
return this.lastLogonField;
}
set
{
this.lastLogonField = value;
}
}
public virtual DateTime? FirstCreated
{
get
{
return this.firstCreatedField;
}
set
{
this.firstCreatedField = value;
}
}
public virtual DateTime? ModifiedDate
{
get
{
return this.modifiedDateField;
}
set
{
this.modifiedDateField = value;
}
}
public virtual int UserTypeID
{
get
{
return this.userTypeIDField;
}
set
{
this.userTypeIDField = value;
}
}
public virtual int StatusID
{
get
{
return this.statusIDField;
}
set
{
this.statusIDField = value;
}
}
public virtual bool PermitRestrictedContentFlag
{
get
{
return this.permitRestrictedContentField;
}
set
{
this.permitRestrictedContentField = value;
}
}
public virtual string Notes
{
get
{
return this.notesField;
}
set
{
this.notesField = value;
}
}
}
}

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="LookupsApp" assembly="LookupsApp" auto-import="true">
<class name="LookupsApp.Model.Users,LookupsApp" table="Users" lazy="true" mutable="true">
<id name="UserID" column="UserID" type="int">
<generator class="native"></generator>
</id>
<property name="ContactID" column="ContactID" type="int"/>
<property name="UserName" column="UserName" type="string"/>
<property name="Password" column="Password" type="string"/>
<property name="PIN" column="PIN" type="int"/>
<property name="Designation" column="Designation" type="string"/>
<property name="NumberOfLogons" column="NumberOfLogons" type="int"/>
<property name="FailedLogins" column="FailedLogins" type="int"/>
<property name="LastFailedLogin" column="LastFailedLogin" type="DateTime"/>
<property name="LastLogon" column="LastLogon" type="DateTime"/>
<property name="FirstCreated" column="FirstCreated" type="DateTime"/>
<property name="ModifiedDate" column="ModifiedDate" type="DateTime"/>
<property name="UserTypeID" column="UserTypeID" type="int"/>
<property name="StatusID" column="StatusID" type="int"/>
<property name="PermitRestrictedContentFlag" column="PermitRestrictedContentFlag" type="Boolean"/>
<property name="Notes" column="Notes" type="string"/>
</class>
<!--<loader query-ref="spValidateUser"/>
</class>-->
<sql-query name="ValidateUser">
<return class="Users" alias="Users">
<return-property name="UserID" column="UserID"></return-property>
<return-property name="ContactID" column="ContactID"></return-property>
</return>
exec spValidateUser:UID,PWD
</sql-query>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

public bool ValidateUser(string userName, string passWord)
{
bool retVar = false;
try
{
using(ISession session=NHibernateSessionFactory.OpenSession())
using (session.BeginTransaction())
{
Users user = new Users();
IQuery query = session.GetNamedQuery("spValidateUser").SetString("UID",userName).SetString("PWD",passWord)
.SetResultTransformer(new NHibernate.Transform.AliasToBeanConstructorResultTransformer
(typeof(Users).GetConstructors()[0]));
IList result = query.List();
UserID = user.UserID;
ContactID = user.ContactID;

if (UserID > 0)
retVar = true;
}

}
catch (Exception e)
{
HttpContext.Current.Response.Write("The error is:" + e.ToString());
retVar = false;
}
return retVar;
}
Full stack trace of any exception that occurs:
Could not load users.hbm.xml file
Name and version of the database you are using:
sql server 2005
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

If i take out <sql-query> thing it is working but is i want to work with stored procedures i need to write that one right.I donot know this is the first time i am using stored procedures,I have no idea.Was that my code wrong,where was wrong.Could you please provide me the soloution.

Read this: http://hibernate.org/42.html


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.