Garfield
05-10-2007, 05:38 AM
Now, I use osiv in my windows application.
In the App.config:
<system.web>
<httpModules>
<add name="Spring"
type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
<add name="OpenSessionInView"
type="Spring.Data.NHibernate.Support.OpenSessionInViewMo dule, Spring.Data.NHibernate"/>
</httpModules>
</system.web>
In the application form:
private void Form1_Load(object sender, EventArgs e)
{
osiv.Open();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
osiv.Close();
}
But it still doesn't work. When I use lazyload, It throw an "...no session." exception. Are there any problems of my code? Is it a right way to use the Nhibernate's lazyload in the windows application? If is not, how can I do?
BTW:
When it run at osiv.Open(), the console's debug infomation:
2007/05/10 12:55:35:453 [DEBUG] Spring.Context.Support.ContextRegistry - Returning context 'Spring.Context.Support.XmlApplicationContext' registered under name 'spring.root'.
2007/05/10 12:55:35:453 [DEBUG] Spring.Objects.Factory.Support.DefaultListableObje ctFactory - Returning cached instance of singleton object 'sessionFactory'.
2007/05/10 12:55:35:453 [DEBUG] Spring.Objects.Factory.Support.DefaultListableObje ctFactory - Object with name 'sessionFactory' is a factory object.
2007/05/10 12:55:35:453 [DEBUG] Spring.Data.NHibernate.Support.OpenSessionInViewMo dule - Creating LazySessionHolder in OpenSessionInView
2007/05/10 12:55:35:453 [DEBUG] Spring.Data.NHibernate.Support.OpenSessionInViewMo dule+LazySessionHolder - Created LazySessionHolder
2007/05/10 12:55:35:468 [DEBUG] Spring.Transaction.Support.TransactionSynchronizat ionManager - Bound value [Spring.Data.NHibernate.Support.OpenSessionInViewMo dule+LazySessionHolder] for key [NHibernate.Impl.SessionFactoryImpl] to thread []
But when it implement a dao code, the console's debug information:
2007/05/10 13:32:12:875 [DEBUG] Spring.Data.NHibernate.SessionFactoryUtils - Opening Hibernate Session
2007/05/10 13:32:14:812 [DEBUG] Spring.Data.NHibernate.HibernateAccessor - Eagerly flushing Hibernate session
2007/05/10 13:32:14:875 [DEBUG] Spring.Data.NHibernate.SessionFactoryUtils - Closing Hibernate Session
The session is closed.
In the App.config:
<system.web>
<httpModules>
<add name="Spring"
type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
<add name="OpenSessionInView"
type="Spring.Data.NHibernate.Support.OpenSessionInViewMo dule, Spring.Data.NHibernate"/>
</httpModules>
</system.web>
In the application form:
private void Form1_Load(object sender, EventArgs e)
{
osiv.Open();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
osiv.Close();
}
But it still doesn't work. When I use lazyload, It throw an "...no session." exception. Are there any problems of my code? Is it a right way to use the Nhibernate's lazyload in the windows application? If is not, how can I do?
BTW:
When it run at osiv.Open(), the console's debug infomation:
2007/05/10 12:55:35:453 [DEBUG] Spring.Context.Support.ContextRegistry - Returning context 'Spring.Context.Support.XmlApplicationContext' registered under name 'spring.root'.
2007/05/10 12:55:35:453 [DEBUG] Spring.Objects.Factory.Support.DefaultListableObje ctFactory - Returning cached instance of singleton object 'sessionFactory'.
2007/05/10 12:55:35:453 [DEBUG] Spring.Objects.Factory.Support.DefaultListableObje ctFactory - Object with name 'sessionFactory' is a factory object.
2007/05/10 12:55:35:453 [DEBUG] Spring.Data.NHibernate.Support.OpenSessionInViewMo dule - Creating LazySessionHolder in OpenSessionInView
2007/05/10 12:55:35:453 [DEBUG] Spring.Data.NHibernate.Support.OpenSessionInViewMo dule+LazySessionHolder - Created LazySessionHolder
2007/05/10 12:55:35:468 [DEBUG] Spring.Transaction.Support.TransactionSynchronizat ionManager - Bound value [Spring.Data.NHibernate.Support.OpenSessionInViewMo dule+LazySessionHolder] for key [NHibernate.Impl.SessionFactoryImpl] to thread []
But when it implement a dao code, the console's debug information:
2007/05/10 13:32:12:875 [DEBUG] Spring.Data.NHibernate.SessionFactoryUtils - Opening Hibernate Session
2007/05/10 13:32:14:812 [DEBUG] Spring.Data.NHibernate.HibernateAccessor - Eagerly flushing Hibernate session
2007/05/10 13:32:14:875 [DEBUG] Spring.Data.NHibernate.SessionFactoryUtils - Closing Hibernate Session
The session is closed.