-->
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.  [ 4 posts ] 
Author Message
 Post subject: List with guid as id
PostPosted: Wed Apr 26, 2006 6:43 am 
Newbie

Joined: Wed Apr 26, 2006 5:28 am
Posts: 18
NHibernate version: 1.0.2.0

Hi,

I have the following tables:
Code:
_____________________
|Bank                 |
|---------------------|
|id : Guid            |
|bankname : wchar(200)|
|_____________________|
                |
                |
               /|\
_____________________
|Constraint           |
|---------------------|
|id : Guid            |
|id_bank : Guid       |
|note : wchar(200)    |
|_____________________|


Every bank can have 0 ore more constraints.

I mapped that as like this:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="BankManager" assembly="BankManager">
   <class name="Bank" table="Bank">
      <id name="Id" type="System.Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
         <column name="id" sql-type="Guid" not-null="true" />
         <generator class="guid" />
      </id>
      <property name="BankName">
         <column name="bankname" length="200" not-null="true"/>
      </property>
      <list name="Constraints" table="Constraint">
         <key column="id_bank" />
         <index column="id" type="Guid"/>
         <one-to-many class="Constraint" />
      </list>
   </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="BankManager" assembly="BankManager">
   <class name="Constraint" table="Constraint">
      <id name="Id" column="id" type="System.Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
         <generator class="guid" />
      </id>
      <property name="Name">
         <column name="name" length="200" not-null="false"/>
      </property>
      <property name="Note">
         <column name="note" length="200" not-null="false"/>
      </property>
   </class>
</hibernate-mapping>

When I call
Code:
session.CreateCriteria(typeof(Bank)).List();


the following error occured.
Code:
{"Could not cast the value in field id__ of type Guid to the Type Int32Type.  Please check to make sure that the mapping is correct and that your DataProvider supports this Data Type."}


The inner exception say:
Code:
{"Unable to cast object of type 'System.Guid' to type 'System.IConvertible'."}


Why does the engine tries to convert a guid to Int? It couldn't be converted to int and it doesn't implement System.IConvertible.


Last edited by NCC-1701-M on Wed May 31, 2006 2:18 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 4:01 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Quote:
Why does the engine tries to convert a guid to Int? It couldn't be converted to int and it doesn't implement System.IConvertible.


Because list indexes are integers. You probably want a <map>.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 1:40 am 
Newbie

Joined: Wed Apr 26, 2006 5:28 am
Posts: 18
sergey wrote:
Quote:
Why does the engine tries to convert a guid to Int? It couldn't be converted to int and it doesn't implement System.IConvertible.


Because list indexes are integers. You probably want a <map>.


Thank you very much. It works now.


Top
 Profile  
 
 Post subject: Re: List with guid as id
PostPosted: Sun Sep 04, 2011 4:33 am 
Newbie

Joined: Sun Sep 04, 2011 4:30 am
Posts: 2
Hi to everybody.

I have the same problem with a GUID identifier.

I cannot execute any CRUD operation to this object.

Could you please provide me some more details about the <map> thing?

Thank you in advance


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