-->
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.  [ 3 posts ] 
Author Message
 Post subject: Can't deserialize byte[] from older version of NHibernate?
PostPosted: Thu May 18, 2006 4:10 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Hi, I recently downloaded the SVN version of NHibernate and was able to build it without a problem. However, I'm running into a problem now with regard to byte[] fields that I'm storing in BLOB fields in the database. From what I can tell so far, the problem only occurs with data that was stored using a previous version of NHibernate. Namely, the release version 1.0.2.0. NHibernate appears to be using BinaryFormatter for serializing/deserializing this data. I think what's happening is that BinaryFormatter is reading data that has a dependency on NHibernate 1.0.2.0 for some reason. I don't know why this should be happening though. Has anyone else ran into this problem? I think the problem is that the public key is different on the version of NHibernate that I built versus the official one. I still don't know why the serialized data should be referencing NHibernate though. What I'm wondering is if I will run into the same problem with the next release version of NHibernate?

Hibernate version: NHibernate SVN 5/17/2006

Mapping documents:

Excluded to keep this message brief for the moment. I can post them if necessary.

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Code:
Unhandled Exception: NHibernate.LazyInitializationException: Failed to lazily in
itialize a collection ---> NHibernate.Type.SerializationException: Could not des
erialize a serializable property:  ---> System.Runtime.Serialization.Serializati
onException: Unable to find assembly 'NHibernate, Version=1.0.2.0, Culture=neutr
al, PublicKeyToken=154fdcb44c4484fc'.
   at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssem
bly()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(Binary
AssemblyInfo assemblyInfo, String name)
   at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String obje
ctName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInf
ormationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, Bi
naryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWi
thMapTyped(BinaryObjectWithMapTyped record)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWi
thMapTyped(BinaryHeaderEnum binaryHeaderEnum)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(He
aderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAp
pDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize
(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCr
ossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize
(Stream serializationStream)
   at NHibernate.Type.SerializableType.FromBytes(Byte[] bytes) in C:\nhibernate\
trunk\nhibernate\src\NHibernate\Type\SerializableType.cs:line 144
   --- End of inner exception stack trace ---
   at NHibernate.Type.SerializableType.FromBytes(Byte[] bytes) in C:\nhibernate\
trunk\nhibernate\src\NHibernate\Type\SerializableType.cs:line 148
   at NHibernate.Type.SerializableType.Get(IDataReader rs, Int32 index) in C:\nh
ibernate\trunk\nhibernate\src\NHibernate\Type\SerializableType.cs:line 66
   at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name) in C
:\nhibernate\trunk\nhibernate\src\NHibernate\Type\NullableType.cs:line 264
   at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, I
SessionImplementor session, Object owner) in C:\nhibernate\trunk\nhibernate\src\
NHibernate\Type\NullableType.cs:line 206
   at NHibernate.Type.AbstractType.Hydrate(IDataReader rs, String[] names, ISess
ionImplementor session, Object owner) in C:\nhibernate\trunk\nhibernate\src\NHib
ernate\Type\AbstractType.cs:line 127
   at NHibernate.Loader.Loader.Hydrate(IDataReader rs, Object id, Object obj, IL
oadable persister, ISessionImplementor session, String[][] suffixedPropertyColum
ns) in C:\nhibernate\trunk\nhibernate\src\NHibernate\Loader\Loader.cs:line 1028
   at NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i, Object
obj, Type instanceClass, EntityKey key, LockMode lockMode, ILoadable rootPersis
ter, ISessionImplementor session) in C:\nhibernate\trunk\nhibernate\src\NHiberna
te\Loader\Loader.cs:line 927
   at NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILo
adable persister, EntityKey key, LockMode lockMode, EntityKey optionalObjectKey,
Object optionalObject, IList hydratedObjects, ISessionImplementor session) in C
:\nhibernate\trunk\nhibernate\src\NHibernate\Loader\Loader.cs:line 884
   at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, En
tityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] l
ockModes, IList hydratedObjects, ISessionImplementor session) in C:\nhibernate\t
runk\nhibernate\src\NHibernate\Loader\Loader.cs:line 818
   at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessi
onImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray
, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean
returnProxies) in C:\nhibernate\trunk\nhibernate\src\NHibernate\Loader\Loader.cs
:line 294
   at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParamet
ers queryParameters, Boolean returnProxies) in C:\nhibernate\trunk\nhibernate\sr
c\NHibernate\Loader\Loader.cs:line 425
   at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionIm
plementor session, QueryParameters queryParameters, Boolean returnProxies) in C:
\nhibernate\trunk\nhibernate\src\NHibernate\Loader\Loader.cs:line 182
   at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Objec
t id, IType type) in C:\nhibernate\trunk\nhibernate\src\NHibernate\Loader\Loader
.cs:line 1505
   at NHibernate.Loader.Collection.CollectionLoader.Initialize(Object id, ISessi
onImplementor session) in C:\nhibernate\trunk\nhibernate\src\NHibernate\Loader\C
ollection\CollectionLoader.cs:line 36
   at NHibernate.Persister.Collection.AbstractCollectionPersister.Initialize(Obj
ect key, ISessionImplementor session) in C:\nhibernate\trunk\nhibernate\src\NHib
ernate\Persister\Collection\AbstractCollectionPersister.cs:line 305
   at NHibernate.Impl.SessionImpl.InitializeCollection(IPersistentCollection col
lection, Boolean writing) in C:\nhibernate\trunk\nhibernate\src\NHibernate\Impl\
SessionImpl.cs:line 4312
   at NHibernate.Collection.AbstractPersistentCollection.Initialize(Boolean writ
ing) in C:\nhibernate\trunk\nhibernate\src\NHibernate\Collection\AbstractPersist
entCollection.cs:line 238
   --- End of inner exception stack trace ---
   at NHibernate.Collection.AbstractPersistentCollection.Initialize(Boolean writ
ing) in C:\nhibernate\trunk\nhibernate\src\NHibernate\Collection\AbstractPersist
entCollection.cs:line 243
   at NHibernate.Collection.AbstractPersistentCollection.Read() in C:\nhibernate
\trunk\nhibernate\src\NHibernate\Collection\AbstractPersistentCollection.cs:line
49
   at NHibernate.Collection.PersistentBag.get_Count() in C:\nhibernate\trunk\nhi
bernate\src\NHibernate\Collection\PersistentBag.cs:line 339
   at Forms.Persistence.Entity.Submission.ToString() in C:\Documents and Setting
s\jemiller\My Documents\Visual Studio 2005\Projects\Forms\FormsLibrary\Forms.Per
sistence.Entity\Submission.cs:line 58
   at System.IO.TextWriter.WriteLine(Object value)
   at System.IO.TextWriter.SyncTextWriter.WriteLine(Object value)
   at System.Console.WriteLine(Object value)
   at FormsConsoleApplication.Program.Main(String[] args) in C:\Documents and Se
ttings\jemiller\My Documents\Visual Studio 2005\Projects\Forms\FormsConsoleAppli
cation\Program.cs:line 42


Name and version of the database you are using:

SQL Server 2005 SP1

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 18, 2006 4:40 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
The problem definitely has to do with the public key. I downgraded to the release version 1.0.2.0. After doing so, I was able to read data that was stored with that version OK and then data stored with my newer build received the error.

My question is, why should there be a dependency on NHibernate stored in the serialized data? In my case, unless it's something else, I'm just storing a byte[] to a SQL Server 2005 image field.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 12:51 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Does anyone from the NHibernate team know the answer to this question? I don't like the idea that the data in the database itself is tied to NHibernate. In theory, I should be able to switch to using some other ORM or just use ADO.NET directly, or even use the Java version of Hibernate. There shouldn't be an NHibernate dependency stored in the database data itself IMHO. Could it be a proxy for that field or something that is being serialized to the database? It seems a little strange to me that it's using BinaryFormatter for a byte[]. It seems like the byte[] should be able to be written out to the database as is.

Here's the mapping file that I'm using:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="FormsLibrary"
    namespace="Forms.Persistence.Entity">
  <class name="File" table="`File`" lazy="false">
    <id name="Id">
      <generator class="identity"/>
    </id>
    <property name="Content" type="BinaryBlob" length="10485760"/>
    <property name="ContentType"/>
    <property name="Name"/>
  </class>
</hibernate-mapping>


And this is the class:

Code:
using System;
using System.Diagnostics;
using System.Text;

namespace Forms.Persistence.Entity
{
    [Serializable]
    public class File
    {
        private byte[] content;
        private string contentType;
        private int id;
        private string name;
        private static TraceSource traceSource = new TraceSource("Forms",
            SourceLevels.All);

        public File()
        {
        }

        public File(string name, string contentType, byte[] content)
        {
            this.name = name;
            this.contentType = contentType;
            this.content = content;
        }

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

        public virtual string ContentType
        {
            get { return contentType; }
            set { contentType = value; }
        }

        public virtual int Id
        {
            get { return id; }
            set { id = value; }
        }

        public virtual string Name
        {
            get { return name; }
            set { name = value; }
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder("{");
            sb.AppendFormat("Id = {0}", Id);
            sb.AppendFormat(", Content = {0}", Content);
            sb.AppendFormat(", ContentType = {0}", ContentType);
            sb.AppendFormat(", Name = {0}", Name);
            sb.Append("}");
            return sb.ToString();
        }
    }
}


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