Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This is my own answer following the suggestion by @Jeroen:</strong></p> <p>I chose the third suggestion given by @Jeroen: "Create your own ILazyInitializer..." (It worked). Demonstration:</p> <p>Below is the way it was made:</p> <p>SerializeSessionTest.spring.config (changes on 'MySessionFactory'): </p> <pre><code>&lt;object id="MySessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate21"&gt; &lt;property name="DbProvider" ref="DbProvider"/&gt; &lt;property name="MappingResources"&gt; &lt;list&gt; &lt;value&gt;assembly://SofPOC.Net4.NH2.Spring13/SofPOC.Questions.SerializeSession.Entities/MasterEtt.hbm.xml&lt;/value&gt; &lt;value&gt;assembly://SofPOC.Net4.NH2.Spring13/SofPOC.Questions.SerializeSession.Entities/DetailEtt.hbm.xml&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="HibernateProperties"&gt; &lt;dictionary&gt; &lt;!--&lt;entry key="connection.provider" value="AcessaDados.NHibernate.Connection.SiefDriverConnectionProvider, AcessaDados"/&gt;--&gt; &lt;entry key="dialect" value="NHibernate.Dialect.SQLiteDialect"/&gt; &lt;entry key="connection.driver_class" value="NHibernate.Driver.SQLite20Driver"/&gt; &lt;entry key="current_session_context_class" value="Spring.Data.NHibernate.SpringSessionContext, Spring.Data.NHibernate21"/&gt; &lt;entry key="hbm2ddl.keywords" value="none"/&gt; &lt;entry key="query.startup_check" value="false"/&gt; &lt;entry key="show_sql" value="true"/&gt; &lt;entry key="format_sql" value="true"/&gt; &lt;entry key="use_outer_join" value="true"/&gt; &lt;entry key="bytecode.provider" value="SofPOC.Questions.SerializeSession.Spring.Data.NHibernate.Bytecode.BytecodeProviderSrlzSupport, SofPOC.Net4.NH2.Spring13"/&gt; &lt;entry key="proxyfactory.factory_class" value="SofPOC.Questions.SerializeSession.Spring.Data.NHibernate.Bytecode.ProxyFactoryFactorySrlzSupport, SofPOC.Net4.NH2.Spring13"/&gt; &lt;/dictionary&gt; &lt;/property&gt; &lt;/object&gt; </code></pre> <p>LazyInitializerSrlzSupport.cs (Here was made ILazyInitializer implementation that supports the ISessionImplementor serialization): </p> <pre><code>/// &lt;summary&gt; /// Here was made ILazyInitializer implementation that supports the ISessionImplementor serialization. /// &lt;/summary&gt; [Serializable] public class LazyInitializerSrlzSupport : global::Spring.Data.NHibernate.Bytecode.LazyInitializer, global::NHibernate.Proxy.ILazyInitializer, AopAlliance.Intercept.IMethodInterceptor { private static readonly MethodInfo exceptionInternalPreserveStackTrace; static LazyInitializerSrlzSupport() { exceptionInternalPreserveStackTrace = typeof(Exception).GetMethod("InternalPreserveStackTrace", BindingFlags.Instance | BindingFlags.NonPublic); } /// &lt;summary&gt; /// TODO: /// &lt;/summary&gt; /// &lt;param name="entityName"&gt;&lt;/param&gt; /// &lt;param name="persistentClass"&gt;&lt;/param&gt; /// &lt;param name="id"&gt;&lt;/param&gt; /// &lt;param name="getIdentifierMethod"&gt;&lt;/param&gt; /// &lt;param name="setIdentifierMethod"&gt;&lt;/param&gt; /// &lt;param name="componentIdType"&gt;&lt;/param&gt; /// &lt;param name="session"&gt;&lt;/param&gt; public LazyInitializerSrlzSupport( string entityName, Type persistentClass, object id, MethodInfo getIdentifierMethod, MethodInfo setIdentifierMethod, IAbstractComponentType componentIdType, ISessionImplementor session) :base(entityName, persistentClass, id, getIdentifierMethod, setIdentifierMethod, componentIdType, session) { this._sessionSrlzSupport = session; } /// &lt;summary&gt; /// This must be the trick. This will be serialized so that /// we can load the session in the "dynamic proxy". /// &lt;/summary&gt; private ISessionImplementor _sessionSrlzSupport; #region ILazyInitializer Members public new void Initialize() { if (this.Session == null) { this.Session = this._sessionSrlzSupport; } base.Initialize(); } public new object GetImplementation() { this.Initialize(); return base.Target; } #endregion #region IMethodInterceptor Members object IMethodInterceptor.Invoke(IMethodInvocation invocation) { try { MethodInfo methodInfo = invocation.Method; object returnValue = base.Invoke(methodInfo, invocation.Arguments, invocation.Proxy); if (returnValue != InvokeImplementation) { return returnValue; } SafeMethod method = new SafeMethod(methodInfo); return method.Invoke(this.GetImplementation(), invocation.Arguments); } catch (TargetInvocationException ex) { exceptionInternalPreserveStackTrace.Invoke(ex.InnerException, new Object[] { }); throw ex.InnerException; } } #endregion } </code></pre> <p>BytecodeProviderSrlzSupport.cs:</p> <pre><code>/// &lt;summary&gt; /// TODO: /// &lt;/summary&gt; public class BytecodeProviderSrlzSupport : global::Spring.Data.NHibernate.Bytecode.BytecodeProvider, global::NHibernate.Bytecode.IBytecodeProvider { private IProxyFactoryFactory proxyFactoryFactory; /// &lt;summary&gt; /// TODO: /// &lt;/summary&gt; /// &lt;param name="listableObjectFactory"&gt;&lt;/param&gt; public BytecodeProviderSrlzSupport(IListableObjectFactory listableObjectFactory) : base(listableObjectFactory) { this.proxyFactoryFactory = new ProxyFactoryFactorySrlzSupport(); } #region IBytecodeProvider Members IProxyFactoryFactory IBytecodeProvider.ProxyFactoryFactory { get { return this.proxyFactoryFactory; } } #endregion } </code></pre> <p>ProxyFactoryFactorySrlzSupport.cs:</p> <pre><code>/// &lt;summary&gt; /// TODO: /// &lt;/summary&gt; public class ProxyFactoryFactorySrlzSupport : global::NHibernate.Bytecode.IProxyFactoryFactory { #region IProxyFactoryFactory Members /// &lt;summary&gt; /// Build a proxy factory specifically for handling runtime lazy loading. /// &lt;/summary&gt; /// &lt;returns&gt;The lazy-load proxy factory.&lt;/returns&gt; public IProxyFactory BuildProxyFactory() { return new ProxyFactorySrlzSupport(); } ///&lt;summary&gt; ///&lt;/summary&gt; public IProxyValidator ProxyValidator { get { return new DynProxyTypeValidator(); } } #endregion } </code></pre> <p>ProxyFactorySrlzSupport.cs:</p> <pre><code>/// &lt;summary&gt; /// TODO: /// &lt;/summary&gt; public class ProxyFactorySrlzSupport : global::Spring.Data.NHibernate.Bytecode.ProxyFactory { private static readonly ILog log = LogManager.GetLogger(typeof(ProxyFactorySrlzSupport)); [Serializable] private class SerializableProxyFactory : global::Spring.Aop.Framework.ProxyFactory { // ensure proxy types are generated as Serializable public override bool IsSerializable { get { return true; } } } public override global::NHibernate.Proxy.INHibernateProxy GetProxy(object id, global::NHibernate.Engine.ISessionImplementor session) { try { // PersistentClass = PersistentClass.IsInterface ? typeof(object) : PersistentClass LazyInitializer initializer = new LazyInitializerSrlzSupport(EntityName, PersistentClass, id, GetIdentifierMethod, SetIdentifierMethod, ComponentIdType, session); SerializableProxyFactory proxyFactory = new SerializableProxyFactory(); proxyFactory.Interfaces = Interfaces; proxyFactory.TargetSource = initializer; proxyFactory.ProxyTargetType = IsClassProxy; proxyFactory.AddAdvice(initializer); object proxyInstance = proxyFactory.GetProxy(); return (INHibernateProxy)proxyInstance; } catch (Exception ex) { log.Error("Creating a proxy instance failed", ex); throw new HibernateException("Creating a proxy instance failed", ex); } } } </code></pre> <p>The complete source is here: <a href="https://dl.dropbox.com/u/49510149/stackoverflow/dotnet/Q11553780.7z" rel="nofollow">Q11553780.7z</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload