nhibernate / nhibernate-core

NHibernate Object Relational Mapper
https://nhibernate.info
GNU Lesser General Public License v2.1
2.13k stars 926 forks source link

Error while deserializing entity with lazy="false" #1894

Open heikar opened 5 years ago

heikar commented 5 years ago

Hi,

i get an strange behavior when i try to deserialize an entity wich is not lazy.

public class Entity
{
    public System.Collections.Generic.ISet<EntityDetail> DetailList { get; set; }
}

using (var session = ...)
{
    var obj = session.Get<Entity>(id);
    using (var stream = ...)
    {
        var serializer = new Hyperion.Serializer();
        serializer.Serialize(obj, stream);
        stream.seek(0, System.IO.SeekOrigin.Begin);
        var objNew = serializer.Deserialize<Entity>(stream);
    }
}

When i invoke the deserializing then the following message occurs:

"Initializing[Unavailable#]-failed to lazily initialize a collection, no session or session was closed"

If i use the BinaryFormatter then the deserialization works.

I dont understand it because the lazy-loading ist disabled for the two entities and the mapped collection.

fredericDelaporte commented 5 years ago

Maybe Hyperion is plagued by the Shrike, wrecking havoc on deserialization.

More seriously, what is this Hyperion serializer? Without complete details (including used mappings), we will likely not reproduce it. So it will be unlikely to be diagnosed.

If possible, consider submitting a test case in a PR, see contributing.

heikar commented 5 years ago

Hi Frédéric,

tanks for your answer.

Hyperion is a high performance serializer.

I will submit the test case and entity/mapping files.

hazzik commented 5 years ago

@heikar what is the full stack trace?

heikar commented 5 years ago

Hi @hazzik,

sorry for the long duration for the answer.

The error occurs e.g. by the deserialization of nested ISet:

Initializing[Unavailable#]-failed to lazily initialize a collection, no session or session was closed

   bei NHibernate.Collection.AbstractPersistentCollection.ThrowLazyInitializationException(String message)
   bei NHibernate.Collection.AbstractPersistentCollection.ThrowLazyInitializationExceptionIfNotConnected()
   bei NHibernate.Collection.AbstractPersistentCollection.Initialize(Boolean writing)
   bei NHibernate.Collection.Generic.PersistentGenericSet`1.Add(T o)
   bei lambda_method(Closure , Object , Object )
   bei Hyperion.SerializerFactories.EnumerableSerializerFactory.<>c__DisplayClass10_1.<BuildSerializer>b__1(Stream stream, DeserializerSession session)
   bei Hyperion.ValueSerializers.ObjectSerializer.ReadValue(Stream stream, DeserializerSession session)
   bei lambda_method(Closure , Stream , DeserializerSession )
   bei Hyperion.ValueSerializers.ObjectSerializer.ReadValue(Stream stream, DeserializerSession session)
   bei Hyperion.Serializer.Deserialize(Stream stream)
   bei NHibernateCollectionTest.Program.Main(String[] args) in

Thank you :)

Regards heikar

ic185054 commented 3 months ago

Hi, Were you able to solve the above issue?