Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate Slow Startup sometimes
    primarykey
    data
    text
    <p>I´m using NHibernate 3 on a new desktop project. I've read about serialize the Configuration Object. I did it but, sometimes it didn´t work. I'm started to think that it´s working only when i start up the app (serialize the configuration object), then close it, and startup again (few seconds later). But if i wait some minutes it didn´t work. I´m talking about 45+ seconds. Other Strange thing if that this just happen on a few machines not all. Some work as expected slow the first time, but faster the nexts startups.</p> <p>Here is my configuration:</p> <p>the class that create the configuration and session factory</p> <pre><code>class NHibernateUnitOfWorkFactory : IUnitOfWorkFactory { public NHibernateUnitOfWorkFactory(string nhibernateConfigPath) { String serializablefilePath = "configuration.serialized"; try { if (IsConfigurationFileValid(serializablefilePath)) { Configuration = LoadConfigurationFromFile(serializablefilePath); } else { // configuration is immutable, store last returned value Configuration = new Configuration(); Configuration.Configure(nhibernateConfigPath); Configuration.AddAssembly(typeof(ObjectEntity).Assembly); SaveConfigurationToFile(serializablefilePath, Configuration); new SchemaUpdate(Configuration).Execute(true, true); } //NHibernateSchemaExport(); } catch (Exception ex) { throw new GenericRepositoryException( string.Format("Error while configuring NHibernate: {0}.", ex.Message) , ex ); } try { SessionFactory = Configuration.BuildSessionFactory(); } catch (Exception ex) { throw new GenericRepositoryException( string.Format("Error while building NH session factory: {0}.", ex.Message) , ex ); } } private Boolean IsConfigurationFileValid(String ConfigFile) { //return File.Exists(ConfigFile); var ass = typeof(ObjectEntity).Assembly; //Assembly.GetCallingAssembly(); if (ass.Location == null) return false; var configInfo = new FileInfo(ConfigFile); var assInfo = new FileInfo(ass.Location); if (configInfo.LastWriteTime &lt; assInfo.LastWriteTime) return false; return true; } private static void SaveConfigurationToFile(String ConfigFile, Configuration configuration) { var file = File.Open(ConfigFile, FileMode.Create); var bf = new BinaryFormatter(); bf.Serialize(file, configuration); file.Close(); } private static Configuration LoadConfigurationFromFile(String ConfigFile) { try { var file = File.Open(ConfigFile, FileMode.Open); var bf = new BinaryFormatter(); var config = bf.Deserialize(file) as Configuration; file.Close(); return config; } catch (Exception) { return null; } } protected ISessionFactory SessionFactory { get; private set; } protected Configuration Configuration { get; private set; } /// &lt;summary&gt; /// Generates table structure inside specified database. /// &lt;/summary&gt; public void NHibernateSchemaExport() { new SchemaExport(this.Configuration).Execute(false, true, false); } #region IUnitOfWorkFactory Members public IUnitOfWork BeginUnitOfWork() { return new NHibernateUnitOfWork(this.SessionFactory.OpenSession()); } public void EndUnitOfWork(IUnitOfWork unitOfWork) { var nhUnitOfWork = unitOfWork as NHibernateUnitOfWork; if (unitOfWork != null) { unitOfWork.Dispose(); unitOfWork = null; } } #endregion #region IDisposable Members public void Dispose() { if (this.SessionFactory != null) { (this.SessionFactory as IDisposable).Dispose(); this.SessionFactory = null; this.Configuration = null; } } #endregion } </code></pre> <p>xml configuration</p> <pre><code>&lt;hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" &gt; &lt;reflection-optimizer use="true"/&gt; &lt;session-factory name="NHibernate.Test"&gt; &lt;property name="connection.driver_class"&gt;NHibernate.Driver.OracleClientDriver&lt;/property&gt; &lt;property name="connection.connection_string"&gt; User Id=xx; Password=xx; Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS= (PROTOCOL=TCP)(HOST=192.168.100.xx)(PORT=1521))) (CONNECT_DATA=(SERVICE_NAME=XE))); &lt;/property&gt; &lt;property name="show_sql"&gt;false&lt;/property&gt; &lt;property name="dialect"&gt;NHibernate.Dialect.Oracle10gDialect&lt;/property&gt; &lt;property name="query.substitutions"&gt;true 1, false 0, yes 'Y', no 'N'&lt;/property&gt; &lt;property name="proxyfactory.factory_class"&gt;NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu&lt;/property&gt; &lt;property name="cache.use_query_cache"&gt;false&lt;/property&gt; &lt;property name="cache.use_second_level_cache"&gt;false&lt;/property&gt; &lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt; &lt;/session-factory&gt; &lt;/hibernate-configuration&gt; </code></pre> <p>Any idea to improve the startup time? </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.
 

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