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: Mapping byte[] to varbinary(MAX): ArrayTypeMismatchException
PostPosted: Tue Sep 18, 2007 8:33 pm 
Newbie

Joined: Mon Apr 30, 2007 6:17 pm
Posts: 14
I am getting this exception when persisting an object:

Quote:
NHibernate.ADOException: Could not save object ---> System.ArrayTypeMismatchException: Source array type cannot be assigned to destination array type.
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
at NHibernate.Type.BinaryType.DeepCopyNotNull(Object value)
at NHibernate.Type.NullableType.DeepCopy(Object val)
at NHibernate.Type.TypeFactory.DeepCopy(Object[] values, IType[] types, Boolean[] copy, Object[] target)
at NHibernate.Impl.SessionImpl.DoSave(Object theObj, EntityKey key, IEntityPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IEntityPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)
--- End of inner exception stack trace ---
at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)
at NHibernate.Impl.SessionImpl.Save(Object obj)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at NHibernate.Engine.Cascades.CascadingAction.ActionSaveUpdateClass.Cascade(ISessionImplementor session, Object child, Object anything)
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, Object child, IType type, CascadingAction action, CascadeStyle style, CascadePoint cascadeTo, Object anything)
at NHibernate.Engine.Cascades.CascadeCollection(CascadingAction action, CascadeStyle style, CollectionType collectionType, IType elemType, Object child, CascadePoint cascadeVia, ISessionImplementor session, Object anything)
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, Object child, IType type, CascadingAction action, CascadeStyle style, CascadePoint cascadeTo, Object anything)
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, IEntityPersister persister, Object parent, CascadingAction action, CascadePoint cascadeTo, Object anything)
at NHibernate.Impl.SessionImpl.DoSave(Object theObj, EntityKey key, IEntityPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IEntityPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)
at NHibernate.Impl.SessionImpl.Save(Object obj)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)


The object that I am saving contains a collection of child objects. These child objects contain a property "Content" of type byte[], like so:

Code:
public byte[] Content
{
   get { return content; }
   set { content = value; }
}


Here's how it's mapped:

Code:
<property name="Content" column="[DocumentContent]" not-null="false" type="BinaryBlob"/>


The column "DocumentContent" is SQL Server 2005 type of varbinary(MAX). For the type attibute in the map I have also tried "Byte[]" and "System.Byte[]". I also tried adding a length attribute with a very large value. These changes made no effect. I always get ArrayTypeMismatchException.

I'm sure I'm missing something obvious, but I'm out of ideas. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 19, 2007 12:33 pm 
Newbie

Joined: Mon Apr 30, 2007 6:17 pm
Posts: 14
I have solved this. Although the type of the property was declared as byte[], the actual type of the value was sbyte[]. The source of the data was sbyte[], and I had simply cast to byte[] whereas I needed to convert it byte by byte.


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.