Hi. I'm trying to get some recods from table using filter and get error, but then I comment 2 lines
Code:
criteria.Add(Expression.Eq("User", userID));
criteria.Add(Expression.Eq("Meeting", meetingID));
runs w.o. errors. The problem as I understand in many-to-one mapping, but i can't find it :(
Hibernate version: 1.2.0 beta2
Mapping documents:Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="DataAccessComponents.Entities" assembly="DataAccessComponents">
<class name="UserMeetingRoleEntity" table="[UserMeetingRole]" lazy="true">
<id name="Id" column="ID" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<many-to-one column="[UserID]" name="User" class="UserEntity" />
<many-to-one column="[MeetingID]" name="Meeting" class="MeetingEntity" />
<property column="[Role]" type="Byte" name="Role" not-null="true" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
public static UserRole GetByUserAndMeeting(Int32 userID, Int32 meetingID)
{
ISession session = SessionProvider.Instance.GetSession();
try
{
ICriteria criteria = session.CreateCriteria(typeof(UserMeetingRoleEntity));
criteria.Add(Expression.Eq("User", userID));
criteria.Add(Expression.Eq("Meeting", meetingID));
IList<UserMeetingRoleEntity> meetingRolesList = criteria.List<UserMeetingRoleEntity>();
if (meetingRolesList != null && meetingRolesList.Count == 1)
{
return (UserRole)meetingRolesList[0].Role;
}
else
{
return UserRole.Unknown;
}
}
catch
{
return UserRole.Unknown;
}
finally
{
SessionProvider.Instance.CloseSession();
}
}
Full stack trace of any exception that occurs:The error occurs on line:
Code:
IList<UserMeetingRoleEntity> meetingRolesList = criteria.List<UserMeetingRoleEntity>();
Code:
could not execute query[SQL: SELECT this_.ID as ID1_1_, this_.[UserID] as column2_1_1_, this_.[MeetingID] as column3_1_1_, this_.[Role] as column4_1_1_, userentity2_.ID as ID0_0_, userentity2_.[Email] as column2_0_0_, userentity2_.[Password] as column3_0_0_, userentity2_.[Type] as column4_0_0_, userentity2_.[Preferences] as column5_0_0_ FROM [UserMeetingRole] this_ left outer join [User] userentity2_ on this_.[UserID]=userentity2_.ID WHERE this_.[UserID] = ? and this_.[MeetingID] = ?]
Inner exception:
Code:
{"There is a problem with your mappings. You are probably trying to map a System.ValueType to a <class> which NHibernate does not allow or you are incorrectly using the IDictionary that is mapped to a <set>. \n\nA ValueType (System.Int32) can not be used with IdentityKey. The thread at google has a good description about what happens with boxing and unboxing ValueTypes and why they can not be used as an IdentityKey: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=bds2rm%24ruc%241%40charly.heeg.de&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3DSystem.Runtime.CompilerServices.RuntimeHelpers.GetHashCode%26sa%3DN%26tab%3Dwg\r\nParameter name: key"}
Name and version of the database you are using:
MS SQL 2005