Open Cyril035 opened 2 years ago
To clarify, when you say "flushed", do you mean that the collections appear empty on the client side? Because usually when talking about NHibernate, "flushing" is about transmitting changes back to the database.
Do they appear empty before server side before serialisation?
On Tue, 4 Jan 2022, 13:38 Cyril035, @.***> wrote:
Hi there,
I used nhibernate v4.1.4 for a long time and all works perfectly until we decide to update to lastest version. (5.3.10) We use it on a wcf service. Data loaded correctly but when objects are serialiazed (with wcf mechanisms) all collections are gone away... :( I precise that all collections load correctly with data inside before serialization.
I try to debug with this snippet
var myObjectWithCollections = Session.Query
().Single(x => x.Id == id); var serializer = new NetDataContractSerializer(); var wcfMessage = new FileStream("soapMsg.xml", FileMode.Create); serializer.WriteObject(wcfMessage , myObjectWithCollections); When serializer.WriteObjectis called, all collection are "flushed" :(
I decide for testing to change the type of one collection from IList to ICollection to test and....tadaaaaaa. It works. Unfortunately, I don't know why and I don't want to change all collection type to this ICollection
After serialization, normally collections are of type PersisentGenericBag which implement ICollection AND IList so it sould work ! I miss something but what ?
NOTE : all my collections are "bags" in my mappings files (hbm.xml). The loading mode was neither eager nor lazy. With 4.1.4 mappings were configured with full loading.
Have you got some ideas cauz I'm a bit confused now :(
Subject posted to stackoverflow https://stackoverflow.com/questions/70569750/nhibernate-bags-are-flushed-during-wcf-serialization too
— Reply to this email directly, view it on GitHub https://github.com/nhibernate/nhibernate-core/issues/2972, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADVWL6Z6SH7IW63QOIJXOTUULS4VANCNFSM5LHLI4UQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you are subscribed to this thread.Message ID: @.***>
Yeah, sorry for this. I mean collections are filled with data from database and after serialization they are empty
Just a guess... Do you have proxyfactory.factory_class
session factory setting set? If yes - try to remove it. If not - try to set it to NHibernate.Bytecode.DefaultProxyFactoryFactory
(which is despite the name is legacy proxy factory)
If it makes no difference - find last version where it works (5.2, 5.1 or 5.0)
I thought about this test, but actually entities are not lazy so no proxy need to be used if I'm right. Anyway I did the test and the pb still there :( I go back to the last working version (4.1.1) and lol... don't work too... Something broken during update. I had to fix the breaking changes. I upgrade from NET4.6.1 to NET48 but same pb.
However, I still have this question in my head... Why it works with ICollection
Does serialization work properly with manually created and populated list? Something like:
var newObj = new MyClass();
newObjc.Collection = new List<Child>();
newObj.Collection.Add(new Child());
serializer.WriteObject(wcfMessage ,newObj);
@bahusoid Yeah, it works. Actually, in session context, NHibernate create a PersisantGenericBag for this collection which is normally serialized. The client should know this type. The wcf fail to serialize this PersistantGenericBag and retrieve a empty generic list instead.
I think it should be closed as external issue because of:
I go back to the last working version (4.1.1) and lol... don't work too... Something broken during update.
Or be converted to discussion.
Hi there,
@bahusoid, even something is going wrong to my project, I don't think it's only the problem. Always this question... why when I change from IList
Hi there,
I used nhibernate v4.1.4 for a long time and all works perfectly until we decide to update to lastest version. (5.3.10) We use it on a wcf service. Data loaded correctly but when objects are serialiazed (with wcf mechanisms) all collections are gone away... :( I precise that all collections load correctly with data inside before serialization.
I try to debug with this snippet
When serializer.WriteObjectis called, all collection are "flushed" :(
I decide for testing to change the type of one collection from IList to ICollection to test and....tadaaaaaa. It works. Unfortunately, I don't know why and I don't want to change all collection type to this ICollection
After serialization, normally collections are of type PersisentGenericBag which implement ICollection AND IList so it sould work ! I miss something but what ?
NOTE : all my collections are "bags" in my mappings files (hbm.xml). The loading mode was neither eager nor lazy. With 4.1.4 mappings were configured with full loading.
Have you got some ideas cauz I'm a bit confused now :(
Subject posted to stackoverflow too