-->
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: NhibernatePropertyAccessException raised when querying
PostPosted: Mon Jul 05, 2010 5:55 am 
Newbie

Joined: Mon Jul 05, 2010 5:38 am
Posts: 2
I have two entities, Test1, and Test2; Please refer
Code:
public class Test1
    {
        public virtual string Id { get; set; }

        public virtual string Name { get; set; }

        public virtual ISet<Test2> Test2s { get; set; }
    }

public class Test2
    {
        public virtual string Id { get; set; }

        public virtual string Description { get; set; }

        public virtual Test1 Test1 { get; set; }
    }


and the Nhibernate configuration for them as following:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Usky.ECommerce.Model.Test.Test1,Usky.ECommerce.Model" table="YJLUO_TEST1">
    <id name="Id" column="Id">
      <generator class="uuid.hex" />
    </id>
    <property name="Name" length="20" type="String" not-null="true"/>
    <set name="Test2s" inverse="true" cascade="all" generic="true" lazy="true">
      <key column="Test1ID" not-null="true"/>
      <one-to-many class="Usky.ECommerce.Model.Test.Test2,Usky.ECommerce.Model"/>
    </set>
  </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Usky.ECommerce.Model.Test.Test2,Usky.ECommerce.Model" table="YJLUO_TEST2">
    <id name="Id" column="Id">
      <generator class="uuid.hex" />
    </id>
    <property name="Description" length="200" type="String"/>
    <many-to-one name="Test1" column="TEST1ID" class="Usky.ECommerce.Model.Test.Test1,Usky.ECommerce.Model" not-null="false"></many-to-one>
  </class>
</hibernate-mapping>


I want to get Test2 by its Description, via
Code:
Test2 t2 = Find(" from Test2 t2 where t2.Description = ?", "AddTest1WithTest2", NHibernate.NHibernateUtil.String)[0];


Then I the Exception is raised as the title, more detais is "Invalid Cast (check your mapping for property type mismatches); setter of Usky.ECommerce.Model.Test.Test2".


Top
 Profile  
 
 Post subject: Re: NhibernatePropertyAccessException raised when querying
PostPosted: Mon Jul 05, 2010 9:24 pm 
Newbie

Joined: Mon Jul 05, 2010 5:38 am
Posts: 2
Can anybody give me some suggestions, pls? Or the informations I provided isn't detailed enough?


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.