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: Databindings and NHibernate
PostPosted: Fri Oct 24, 2008 5:15 am 
Newbie

Joined: Fri Oct 24, 2008 4:37 am
Posts: 11
Location: Planet earth
Hi All.

I am having a issue in binding a IList provided from NHibernate(A product that I am new to, but I think IT REALLY #¤%#¤%&#¤%&% ROCKS)
I am completly lost, because when I call my userGetAll() method from anywhere else, it works as expected, but as soon I try to use databindings, it is not working.
Can anyone see where my malfunction is(besides the one in my head)?

NHibernate version: 2

Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="model" assembly="Monit">
<class
name="cUser"
table="tbUsers"
mutable="true"
>
<id name="ID" column="ID">
<generator class="identity" />
</id>

<property name="LoginName" column="LoginName" />
<property name="Password" column="Password" />
<property name="Name" column="Name" />
<property name="SurName" column="SurName" />
<property name="Email" column="email" />
<property name="CreateDate" column="CreateDate" />
<property name="EmployNo" column="EmployNo" />
<property name="point" column="points" />

<bag name="Roles" table="tbUserRoles" lazy="true" >
<key column="UserID"></key>
<many-to-many class="cRole" column="RoleID" />
</bag>


</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
public System.Collections.Generic.IList<cUser> userGetAll()
{

BeginTrans();
System.Collections.Generic.IList<cUser> r = _session.CreateQuery("from cUser").List< cUser >();
CommitTrans();
return r;
}


BeginTrans() / EndTrans() is just a lazy version of starting and ending a transaction. Methodes sees if there is a running transaction and acts after this information


Full stack trace of any exception that occurs:
NHibernate.Exceptions.GenericADOException: Could not execute query[SQL: SQL not available] ---> System.ArgumentException: The value \"MonitCMS.model.cUser\" is not of type \"MonitCMS.model.cUser\" and cannot be used in this generic collection.
Parameter name: value
at System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value, Type targetType)
at System.Collections.Generic.List`1.VerifyValueType(Object value)
at System.Collections.Generic.List`1.System.Collections.IList.Add(Object item)
at NHibernate.Util.ArrayHelper.AddAll(IList to, IList from)
at NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results)
at NHibernate.Impl.SessionImpl.List(String query, QueryParameters queryParameters, IList results)
--- End of inner exception stack trace ---
at NHibernate.Impl.SessionImpl.List(String query, QueryParameters queryParameters, IList results)
at NHibernate.Impl.SessionImpl.List[T](String query, QueryParameters parameters)
at NHibernate.Impl.QueryImpl.List[T]()
at MonitCMS.dataaccess.ORM.DataAccess.userGetAll()" string



Name and version of the database you are using:
MsSQL 2K5


Error only occures when I use ObjectDataSource and binds a ASP component to it. (In this case a dropdown list) the binding code is:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="userGetAll" TypeName="MonitCMS.dataaccess.ORM.DataAccess"></asp:ObjectDataSource>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ObjectDataSource1"
DataTextField="ID" DataValueField="Name">

Can someone please tell me where my missing link is? And very sorry for the clueness in this one, I am sure I have overlooked something.

_________________
With respect,
Morten


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2008 9:52 am 
Beginner
Beginner

Joined: Sun Oct 22, 2006 12:06 pm
Posts: 39
well. this is kind a ObjectDatasourceIssue, because it has it's own weird ways to load, update and delete functions.

Personally I hate ObjectDatasource, so I'd recommend you to use a NhibernateDatasource insted,

check out this link

http://www.codeproject.com/KB/aspnet/NH ... ource.aspx


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.