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.  [ 2 posts ] 
Author Message
 Post subject: Problem with session.Flush()
PostPosted: Tue Dec 12, 2006 8:40 am 
Beginner
Beginner

Joined: Wed Nov 22, 2006 5:59 am
Posts: 29
Location: London
Version: 1.2.0 bata

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="CCM.Data.Tables" assembly="CCM.Data" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:nhibernate-mapping-2.2 nhibernate-mapping.xsd">
<class name="SCControlFunction" table="SC_CONTROL_FUNCTION">
<id name="IDControlFunction" type="int" column="ID_CONTROL_FUNCTION">
<generator class="native" />
</id>
<property name="ControlFunctionName" type="string" column="CONTROL_FUNCTION_SNAME" length="80" />
<property name="ControlFunctionDesc" type="string" column="CONTROL_FUNCTION_DESC" length="80" />
<property name="CertifyUnit" type="string" column="CERTIFY_UNIT" length="3" />
<property name="CreateDate" type="DateTime" column="CREATE_DATE" />
<many-to-one name="CreateUser" class="OCUser" column="CREATE_USER_ID" />
<property name="ChangeDate" type="DateTime" column="CHANGE_DATE" />
<many-to-one name="ChangeUser" class="OCUser" column="CHANGE_USER_ID" />
<bag name="UserFunctions" cascade="all" fetch="select" lazy="false">
<key column="ID_CONTROL_FUNCTION" />
<one-to-many class="SCUserFunctionLink"/>
</bag>
</class>
</hibernate-mapping>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="CCM.Data.Tables" assembly="CCM.Data" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:nhibernate-mapping-2.2 nhibernate-mapping.xsd">
<class name="SCUserFunctionLink" table="SC_USER_FUNCTION_LINK">
<composite-id>
<key-many-to-one name="IDUser" class="OCUser" column="ID_USER" />
<key-many-to-one name="IDControlFunction" class="SCControlFunction" column="ID_CONTROL_FUNCTION" />
</composite-id>
<many-to-one name="IDValidation" class="OCUser" column="ID_VALIDATION" />
<property name="CreateDate" type="DateTime" column="CREATE_DATE" />
<many-to-one name="CreateUser" class="OCUser" column="CREATE_USER_ID" />
<property name="ChangeDate" type="DateTime" column="CHANGE_DATE" />
<many-to-one name="ChangeUser" class="OCUser" column="CHANGE_USER_ID" />
</class>
</hibernate-mapping>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="CCM.Data.Tables" assembly="CCM.Data" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:nhibernate-mapping-2.2 nhibernate-mapping.xsd">
<class name="OCUser" table="OC_USER">
<id name="IDUser" type="int" column="ID_USER">
<generator class="native" />
</id>
<property name="FirstName" type="string" column="FIRST_NAME" />
<property name="LastName" type="string" column="LAST_NAME" />
<many-to-one name="IDOrganisation" class="OCOrganisationHierarchy" column="ID_ORGANISATION" />
<property name="EmailAddress" type="string" column="EMAIL_ADDRESS" />
<property name="JobTitle" type="string" column="JOB_TITLE" />
<property name="JobTitle" type="string" column="JOB_TITLE" />
<property name="CreateDate" type="DateTime" column="CREATE_DATE" />
<many-to-one name="CreateUser" class="OCUser" column="CREATE_USER_ID" />
<property name="ChangeDate" type="DateTime" column="CHANGE_DATE" />
<many-to-one name="ChangeUser" class="OCUser" column="CHANGE_USER_ID" />
<bag name="UserFunctions" cascade="all" fetch="select" lazy="true">
<key column="ID_USER" />
<one-to-many class="SCUserFunctionLink"/>
</bag>
</class>
</hibernate-mapping>


Code used for testing:

Code:
            using (Session session = new Session())
            {
                SCControlFunction function = Repository.Get<SCControlFunction>(12125);
                Assert.IsNotNull(function);
                Assert.AreEqual(12125, function.IDControlFunction);
                foreach (SCUserFunctionLink link in function.UserFunctions)
                {
                    Assert.IsNotNull(link);
                }
                session.Success();
            }


I am having a problem in which I get an SCControlFunction object by ID using my own Get function. I also have a class Session which wraps an ISession to allow me to use lazy loading. This class implements IDisposable and in my Dispose method I call session.Flush() etc. The problem is that I get the following error when Flush() is called:


System.ArgumentException: 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>.

A 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&l ... 26tab%3Dwg
Parameter name: key


Doeas anyone have any idea why I am getting this error. as I can't see any major problems with my mapping files.


Top
 Profile  
 
 Post subject: Equals & Hashcode
PostPosted: Tue Dec 12, 2006 2:29 pm 
Beginner
Beginner

Joined: Thu Apr 27, 2006 12:19 pm
Posts: 33
Location: Seattle, WA
I'm not really sure what the issue is. Do the classes involved with your composite key properly override Equals and Hashcode?


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