-->
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.  [ 5 posts ] 
Author Message
 Post subject: Error on param id when loading an object
PostPosted: Fri Sep 30, 2005 6:36 am 
Newbie

Joined: Wed Sep 28, 2005 3:44 pm
Posts: 5
I am newbie to nHibernate.

I need to update info via this object . I am getting error "identifier type mismatch Parameter name: id " on the page load.

Code:
int id = Convert.ToInt32(Request.QueryString["id"]);
Configuration cfg = new Configuration();
cfg.AddAssembly("Domain");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
Coupon objCoupon = null;
objCoupon = (Coupon)session.Load(typeof(Coupon),id);  <--- the error
txtCouponTitle.Text = objCoupon.CouponTitle;
imgCoupon.ImageUrl = "uploadimages\\" + objCoupon.CouponImage;
session.Close();


Stack trace:
Code:
[ArgumentException: identifier type mismatch
Parameter name: id]
   NHibernate.Engine.Key..ctor(Object id, IType identifierType, Object identifierSpace, Type clazz, Boolean isBatchLoadable) +188
   NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted) +231
   NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation) +185
   NHibernate.Impl.SessionImpl.Load(Type clazz, Object id) +37
   WebUI.EditCoupon.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\webui\editcoupon.aspx.cs:52
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731


HBM.XML File:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <!-- generated using NHibernate.hbm.cst, see http://www.intesoft.net/nhibernate for notes and latest version -->
   <class name="Domain.Coupon, Domain" table="Coupon">
      <id name="Id" type="Decimal" unsaved-value="0">
         <column name="CouponID" sql-type="Int32" not-null="true" unique="true" index="PK_SGCoupon"/>
         <generator class="native" />
      </id>
      <property name="CouponTitle" type="String">
         <column name="CouponTitle" length="250" sql-type="varchar" not-null="false"/>
      </property>
      <property name="CouponImage" type="String">
         <column name="CouponImage" length="250" sql-type="varchar" not-null="false"/>
      </property>
      <property name="CouponType" type="Byte">
         <column name="CouponType" sql-type="tinyint" not-null="false"/>
      </property>
      <many-to-one name="Store" class="Domain.Store, Domain">
         <column name="StoreId" sql-type="numeric" not-null="false"/>
      </many-to-one>
   </class>
</hibernate-mapping>


Any solution to this? Am I going somewhere wrong with the Session.Load()?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 6:47 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Id is mapped as a Decimal, but you are passing Int32 to Load. That's the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 7:32 am 
Newbie

Joined: Wed Sep 28, 2005 3:44 pm
Posts: 5
I changed it to
Decimal id = Convert.ToInt32(Request.QueryString["id"]);
....
...
objCoupon = (Coupon)session.Load(typeof(Coupon),id);

and Now I am recieving this error "identifier type mismatch Parameter name: id "

??


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 7:36 am 
Newbie

Joined: Wed Sep 28, 2005 3:44 pm
Posts: 5
Herez the exact code

Code:
Decimal id = Convert.ToDecimal(Request.QueryString["id"]);
Configuration cfg = new Configuration();
cfg.AddAssembly("Domain");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
Coupon objCoupon = (Coupon)session.Load(typeof(Coupon),id);
session.Close();


Code:
Error : identifier type mismatch Parameter name: id

Stack Trace :
[ArgumentException: identifier type mismatch
Parameter name: id]
   NHibernate.Engine.Key..ctor(Object id, IType identifierType, Object identifierSpace, Type clazz, Boolean isBatchLoadable) +188
   NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted) +231
   NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation) +185
   NHibernate.Impl.SessionImpl.Load(Type clazz, Object id) +37
   WebUI.EditCoupon.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\webui\editcoupon.aspx.cs:51
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 7:48 am 
Newbie

Joined: Wed Sep 28, 2005 3:44 pm
Posts: 5
The HBM file was not properly configured. I didnt realize that the field was numeric instead of integer.

Thanks for the tip, anyways :)


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