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.