-->
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.  [ 1 post ] 
Author Message
 Post subject: Problems with IDictionary map and merge
PostPosted: Tue Nov 24, 2009 5:29 am 
Newbie

Joined: Wed Nov 04, 2009 10:09 am
Posts: 1
Hi All,

I'm a relative newcomer to nhibernate and have just stumbled across an issue with the merge method for a detached entity containing a IDictionary <map> collection. Each time merge is called an Invalid cast exception is thown (System.InvalidCastException: Specified cast is not valid..): stack trace as follows.

Code:
ReplaceElements(Object original, Object target, Object owner, IDictionary copyCache, ISessionImplementor session)
NHibernate.Type.CollectionType.Replace(Object original, Object target, ISessionImplementor session, Object owner, IDictionary copyCache)
NHibernate.Type.TypeFactory.Replace(Object[] original, Object[] target, IType[] types, ISessionImplementor session, Object owner, IDictionary copiedAlready)
NHibernate.Event.Default.DefaultMergeEventListener.CopyValues(IEntityPersister persister, Object entity, Object target, ISessionImplementor source, IDictionary copyCache)
NHibernate.Event.Default.DefaultMergeEventListener.EntityIsDetached(MergeEvent event, IDictionary copyCache)
NHibernate.Event.Default.DefaultMergeEventListener.OnMerge(MergeEvent event, IDictionary copyCache)
NHibernate.Event.Default.DefaultMergeEventListener.OnMerge(MergeEvent event)
NHibernate.Impl.SessionImpl.FireMerge(MergeEvent event)
NHibernate.Impl.SessionImpl.Merge(String entityName, Object obj)
NHibernate.Impl.SessionImpl.Merge(Object obj)


A simplification of the mapping being used is:
Code:
  <class name="Employee" table="Per_Employees" dynamic-update="true" lazy="false">
    <!-- Identity mapping -->
    <id name="Id">
      <column name="EmployeeID" />
      <generator class="native" />
    </id>

    <!-- one-to-many mapping: 'EmployeeAttributes' -->
    <map name="EmployeeAttributes" table="Per_EmployeeAttributes" lazy="false">
      <key column="EmployeeID" not-null="true" />
      <index column="AttributeID" type="Int32" />
      <element column="ValueID" type="Int32" />
    </map>

  </class> 

And class:
Code:
public class Employee
{
    private int _id;
    private IDictionary<int, int> _employeeAttributes;
    public virtual int Id
        {
            get { return _id; }
            private set { _id = value; }
        }

     public virtual IDictionary<int, int> EmployeeAttributes
        {
            get { return _employeeAttributes; }
            private set { _employeeAttributes = value; }
        }
}

Using SaveOrUpdate seems to work but so far we're preferring Merge as dynamic updating doesn't seem to work with SaveOrUpdate with a detached architecture.

I've been searching around the internet for a day or so with no insight, so any guidance here would be hugely appreciated.

Thanks in advance,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.