-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with my many-to-one mapping?
PostPosted: Mon Nov 13, 2006 1:48 pm 
Newbie

Joined: Mon Nov 13, 2006 1:21 pm
Posts: 1
Location: Ukraine
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 2:20 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This looks like a bug. Please submit it to JIRA including code and mappings required to reproduce it (important!). Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 11:59 am 
Contributor
Contributor

Joined: Tue May 30, 2006 1:25 am
Posts: 29
Try to use the new expression IdEq from SVN of NHb.

_________________
Fabio Maulo.


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