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: identifier type mismatch on session.Get function
PostPosted: Wed Oct 11, 2006 7:25 am 
Regular
Regular

Joined: Mon Oct 02, 2006 12:03 pm
Posts: 62
Hello forum,

I'm testing and experimenting eith NHibernate and I've created a simple Role-User relation in my Database. So,

ROLE (1) ---------(N) USER

User can belongs to 1 role and 1 role can contain N users. So,

Code:
User-->
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="PersistentClasses.User, PersistentClasses" table="USUARIS">
      <id name="Login" column="LOGIN" type="String" length="25">
         <generator class="assigned" />
      </id>
      <property name="Password" column="PASSWORD" type="String" length="10"/>
        <property name="Name" column="NOM" type="String" length="50"/>
        <many-to-one name="Rol" column="ROL" unique="true" not-null="true"/>
        <!--<property name="Rol" column="ROL" type="Int16"/> -->
   </class>
</hibernate-mapping>


Rol -->
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="PersistentClasses.Role, PersistentClasses" table="ROLS">
      <id name="Rol" column="ROL" type="Int32">
         <generator class="assigned" />
      </id>
      <property name="Descripcio" column="DESCRIPCIO" type="String" length="50"/>
      <set name="Users" inverse="true">
         <key column="ROL"/>
         <one-to-many class="PersistentClasses.User, PersistentClasses"/>
      </set>
   </class>
</hibernate-mapping>



And I can save them correctly into my database, but when I want to get one user (for example) NHinernate throws me an exception with the follow message : "identifier type mismtch"

The code is:

Code:
      public PersistentClasses.User getUser(string login)
      {
         PersistentClasses.User user = new User();
         user.Login = login;

         NHibernate.ITransaction transaction = this.session.BeginTransaction();

         this.session.Get(typeof(PersistentClasses.User),user);

         transaction.Commit();
         return user;
      }


Mmm, can you help me, please.

Note: I've tried replace Get function for Load function and the result is the same.

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: identifier type mismatch on session.Get function
PostPosted: Wed Oct 11, 2006 7:53 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
jeusdi wrote:
Hello forum,


Code:
      public PersistentClasses.User getUser(string login)
      {
         PersistentClasses.User user = new User();
         user.Login = login;

         NHibernate.ITransaction transaction = this.session.BeginTransaction();

         this.session.Get(typeof(PersistentClasses.User),user);

         transaction.Commit();
         return user;
      }


Mmm, can you help me, please.



try

Code:
      public PersistentClasses.User getUser(string login)
      {
         NHibernate.ITransaction transaction = this.session.BeginTransaction();

         PersistentClasses.User user = (PersistentClasses.User)this.session.Get(typeof(PersistentClasses.User), login);

         transaction.Commit();
         return user;
      }


or (in .net 2.0)

Code:
         PersistentClasses.User user = this.session.Get<PersistentClasses.User>(login);

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 6:18 am 
Regular
Regular

Joined: Mon Oct 02, 2006 12:03 pm
Posts: 62
Thanks, It's solved. Mmm, but now, I have other problem:

When I execute:

Code:
            NHibernate.ITransaction transaction = this.session.BeginTransaction();
            user = (PersistentClasses.User)this.session.Get(typeof(PersistentClasses.User),login);
            transaction.Commit();

throws an exception with the follow message:

Quote:
Invalid mapping information specified for type PersistentClasses.Role, check your mapping file for property type mismatches

Invalid converstion



I think that, It says me that Role.hbm.xlm is wrong. But, I've saved several "roles" previously whitout problems.

The configuration files are in first post.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 12:26 pm 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
jeusdi wrote:
Quote:
Invalid mapping information specified for type PersistentClasses.Role, check your mapping file for property type mismatches

Invalid converstion



I think that, It says me that Role.hbm.xlm is wrong. But, I've saved several "roles" previously whitout problems.


As per error, does the Role have property "ROL" of type int, "Descripcio" of type string and "Users" of type ISet (or ICollection)?

Gert

_________________
If a reply helps You, rate it!


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.