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: PropertyAccessException using bag with compisite-id
PostPosted: Mon Mar 02, 2009 8:31 am 
Newbie

Joined: Fri Apr 25, 2008 8:19 am
Posts: 17
I use an domain object delegation with a composite id projno and index. In this object i insert a bag. When i create a new delegation without voucheurs and want to save it the following exception raised:

NHibernate.PropertyAccessException : Invalid Cast (check your mapping for property type mismatches); setter of domain.Delegation
----> System.InvalidCastException : Die angegebene Umwandlung ist ungültig.

In other domain objects i use one key-column and everything works fine. What is wrong in this implementation?

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="domain" assembly="Base">
  <class name="Delegation" table="delegation">
    <composite-id unsaved-value="none">
      <key-property name="ProjNo" column="projno" access="field.pascalcase-underscore" />
      <key-property name="Index" column="index" access="field.pascalcase-underscore" />
    </composite-id>
    <bag name="Voucheur" access="field.pascalcase-underscore" lazy="true" inverse="true" cascade="all">     
      <key>
        <column name="projmo"/>
        <column name="index"/>
      </key>     
      <one-to-many class="Voucheur" />
    </bag>
  </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="domain" assembly="Base">
  <class name="Voucheur" table="voucheur">
    <id name="VoucheurNo" column="voucheurno" access="field.pascalcase-underscore">
      <generator class="assigned" />
    </id>
    <many-to-one not-found="ignore" name="Einsatz" access="field.pascalcase-underscore">
      <column name="projnp"/>
      <column name="index"/>     
    </many-to-one>
  </class>
</hibernate-mapping>

public class Delegation
{
    private string _ProjNo;
    public virtual string ProjNo
    {
        get { return _ProjNo; }
        set { _ProjNo = value; }
    }

   private int? _Index;
    public virtual int? Index
    {
        get { return _Index; }
    }
       
    private IList<Voucheur> _Voucheurs = new List<Voucheur>();
    public virtual IList<Voucheur> Voucheurs
    {
        get { return _Voucheurs; }
    }
}

public class Voucheur
{
    protected int? _VoucheurNo;
    public virtual int? VoucheurNo
    {
        get { return _VoucheurNo; }
        set { _VoucheurNo = value; }
    }

    protected Delegation _Delegation;
    public virtual Delegation Delegation
    {
        get { return _Delegation; }
        set { _Delegation = value; }
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 06, 2009 9:38 am 
Newbie

Joined: Fri Apr 25, 2008 8:19 am
Posts: 17
Has nobody this issue?


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.