-->
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.  [ 2 posts ] 
Author Message
 Post subject: Nhibernate execute fails: IndexOutOfRangeException
PostPosted: Sun Apr 11, 2010 4:07 pm 
Newbie

Joined: Sun Apr 11, 2010 1:48 pm
Posts: 2
Greetings,

I am currently smashing my head into the wall and for all the results i have found towards the issue; say i should be doing the right thing.

so here goes:
I have a quite simpel datamodel.
login --> user

where the logintabel has the following columns:
- login_unique (PK)
- user_unique (FK)
- username varchar(250)
- password varchar(256)
- usergroup int (FK)

and the usertabel has the following columns:
- user_unique (PK)
- firstname
- prefix
- lastname
- country (FK)

so i made a simpel store procedure:
select login_unique, user_unique, username, password, usergroup from
project_login as l
where l.password = @password and l.username = @username

so i used a Nhibernate mapping to call it:
<sql-query name="spProject_login">
<return class="Project.Core.Domain.project_login, Project.Core">
<return-property name="firstname" column="firstname" />
<return-property name="lastname" column="lastname" />
</return>
exec SPProject_Login :@username, :@password
</sql-query>

and the project_login class
project_login is a class with the following for each of the columns.
private Guid _login_unique;
public virtual Guid login_unique
{
get { return _login_unique; }
set { _login_unique = value; }
}

tipped off with and Ilist for the userclass, which i bound by the one-to-many relation..?

private IList<user> _user = new List<user>();
public virtual IList<user> user
{
get{ return _user;}
protected set { _user = value; }
}

and i call it:
IQuery query = NHibernateSession.GetNamedQuery("spProject_login");
query.SetString("@username", username);
query.SetString("@password", password);
return query.List<project_login>() as List<project_login>;

now i can call the function with some parameters and Nhibenate hydrates it towards the database like i would expect:
exec sp_executesql N'exec SPProject_Login @p0, @p1',N'@p0 nvarchar(8),@p1 nvarchar(8)',@p0=N'username',@p1=N'password'

if i execute that directly on the data, it returns values foreach of the columns in project_login.

so what is nhibernate telling me?

thanks for reading the rather long post.

Kinjara


Top
 Profile  
 
 Post subject: Re: Nhibernate execute fails: IndexOutOfRangeException
PostPosted: Sun Apr 11, 2010 4:08 pm 
Newbie

Joined: Sun Apr 11, 2010 1:48 pm
Posts: 2
and for those that wonder about the stack trace:

[IndexOutOfRangeException: login1_1_0_]
System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName) +5031294
System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) +67
NHibernate.Driver.NHybridDataReader.GetOrdinal(String name) +40
NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name) +74
NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner) +55
NHibernate.Loader.Loader.GetKeyFromResultSet(Int32 i, IEntityPersister persister, Object id, IDataReader rs, ISessionImplementor session) +172
NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies) +295
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +1299
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +106
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +172

[ADOException: could not execute query
[ exec SPProject_Login @p0, @p1 ]
Name:@username - Value:username Name:@password - Value:password
[SQL: exec SPProject_Login @p0, @p1]]
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +339
NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) +46
NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) +155
NHibernate.Loader.Custom.CustomLoader.List(ISessionImplementor session, QueryParameters queryParameters) +52
NHibernate.Impl.SessionImpl.ListCustomQuery(ICustomQuery customQuery, QueryParameters queryParameters, IList results) +247
NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters, IList results) +220
NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters) +202
NHibernate.Impl.SqlQueryImpl.List() +231
Project.Core.DataInterfaces.LoginDao.GetLoginByUserNameAndPassword(String username, String password) in C:\Users\Username\documents\visual studio 2010\Projects\TestCase\Project.Data\LoginDao.cs:44
Project.Web._Default.PageLoad() in C:\Users\Username\documents\visual studio 2010\Projects\TestCase\TestCase\Default.aspx.cs:13
Project.Web.BasePage.Page_Load(Object sender, EventArgs e) in C:\Users\Username\documents\visual studio 2010\Projects\TestCase\TestCase\App_Code\BasePage.cs:21
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +115
System.Web.UI.Control.LoadRecursive() +49
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207


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