PDA

View Full Version : a possible bug between AOP and Spring.Data.Orm.NHibernate


jason_yu
04-05-2006, 04:26 AM
Hi, all,
In my project, I integrated the Spring.Data.Orm.NHibernate into spring.core, following is my config file named "Spring-NHibernateContext.xml":

<objects xmlns='http://www.springframework.net'>

<object id="DbProvider"
type="Spring.Data.Support.SqlProvider, Spring.Data">

<property name="ConnectionString"
value="Data Source=server-db;Database=Recipes;User ID=user;Password=;Trusted_Connection=False"/>
</object>

<object id="SessionFactory" type="Spring.Data.Orm.NHibernate.LocalSessionFactoryObje ct, Spring.Data.Orm.NHibernate">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
<value>Company.Domain</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>

<entry key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"/>

<entry key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"/>

<entry key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"/>

</dictionary>
</property>

</object>

<object id="CommonDAO" type="Company.DAO.CommonDAO, AecOceansoft.DAO">
<property name="SessionFactory" ref="SessionFactory"/>
</object>

<object id="NHibernateTransactionManager"
type="Spring.Data.Orm.NHibernate.HibernateTransactionMan ager, Spring.Data.Orm.NHibernate">

<property name="DbProvider" ref="DbProvider"/>
<property name="sessionFactory" ref="SessionFactory"/>

</object>
</objects>


So, the web application can work well, the business components can access database successfully, however, web application will load the Nhibernate configuration circularly when i add some Interceptors to spring container, the application can not run, stopping at starting the web application, following is my another config file for Interceptors:

<objects xmlns="http://www.springframework.net">

<object id="BusinessLogic" type="MyClassLib.BusinessLogic,MyClassLib" />

<object id="MyInterceptor" type="MyClassLib.MyInterceptor,MyClassLib" />

<object id ="myAutoProxy" type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxy Creator">

<property name="InterceptorNames">
<list>
<value>MyInterceptor</value>
</list>
</property>
<property name="ProxyTargetType">
<value>false</value>
</property>

<property name="ExposeProxy">
<value>false</value>
</property>
<property name="Optimize">
<value>false</value>
</property>
<property name="ObjectNames">
<list>
<value>B*</value>
</list>
</property>
</object>
</objects>


following is the source code for Interceptor named MyInterceptor :
public class MyInterceptor : IMethodInterceptor
{
private static ILog LOG = LogManager.GetLogger("MY PROGRAM");


public object Invoke(IMethodInvocation invocation)
{

Console.Out.WriteLine("Intercepted call : about to invoke next item in chain...");
object returnValue = invocation.Proceed();
Console.Out.WriteLine("Intercepted call : returned " + returnValue);
return returnValue;
}


}

The web application will load the Nhibernate configuration circularly when i begin to start and debug, the log4net output the following information circularly :


'aspnet_wp.exe' (Managed): Loaded 'x-1avana', No symbols loaded.
NHibernate.Impl.SessionFactoryObjectFactory: 2006-04-05 11:22:41,011 [1816] INFO NHibernate.Impl.SessionFactoryObjectFactory [(null)] - no name configured
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,011 [1816] INFO NHibernate.Cfg.Configuration [(null)] - Searching for mapped documents in assembly: AecOceansoft.Domain
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,011 [1816] INFO NHibernate.Cfg.Configuration [(null)] - Found mapping documents in assembly: AecOceansoft.Domain.Employee.hbm.xml
NHibernate.Dialect.Dialect: 2006-04-05 11:22:41,027 [1816] INFO NHibernate.Dialect.Dialect [(null)] - Using dialect: NHibernate.Dialect.MsSql2000Dialect
NHibernate.Cfg.Binder: 2006-04-05 11:22:41,027 [1816] INFO NHibernate.Cfg.Binder [(null)] - Mapping class: AecOceansoft.Domain.Employee -> Employee
Spring.Data.Orm.NHibernate.LocalSessionFactoryObje ct: 2006-04-05 11:22:41,027 [1816] INFO Spring.Data.Orm.NHibernate.LocalSessionFactoryObje ct [(null)] - Building new Hibernate SessionFactory
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,027 [1816] INFO NHibernate.Cfg.Configuration [(null)] - processing one-to-many association mappings
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,027 [1816] INFO NHibernate.Cfg.Configuration [(null)] - processing one-to-one association property references
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,027 [1816] INFO NHibernate.Cfg.Configuration [(null)] - processing foreign key constraints
NHibernate.Dialect.Dialect: 2006-04-05 11:22:41,027 [1816] INFO NHibernate.Dialect.Dialect [(null)] - Using dialect: NHibernate.Dialect.MsSql2000Dialect
NHibernate.Cfg.SettingsFactory: 2006-04-05 11:22:41,027 [1816] INFO NHibernate.Cfg.SettingsFactory [(null)] - use outer join fetching: True
NHibernate.Connection.ConnectionProviderFactory: 2006-04-05 11:22:41,027 [1816] INFO NHibernate.Connection.ConnectionProviderFactory [(null)] - Intitializing connection provider: NHibernate.Connection.DriverConnectionProvider
NHibernate.Connection.ConnectionProvider: 2006-04-05 11:22:41,027 [1816] INFO NHibernate.Connection.ConnectionProvider [(null)] - Configuring ConnectionProvider
NHibernate.Cfg.SettingsFactory: 2006-04-05 11:22:41,027 [1816] INFO NHibernate.Cfg.SettingsFactory [(null)] - Optimize cache for minimal puts: False
NHibernate.Cfg.SettingsFactory: 2006-04-05 11:22:41,027 [1816] INFO NHibernate.Cfg.SettingsFactory [(null)] - Query language substitutions: {}
NHibernate.Cfg.SettingsFactory: 2006-04-05 11:22:41,043 [1816] INFO NHibernate.Cfg.SettingsFactory [(null)] - cache provider: NHibernate.Cache.HashtableCacheProvider
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,043 [1816] INFO NHibernate.Cfg.Configuration [(null)] - instantiating and configuring caches
NHibernate.Impl.SessionFactoryImpl: 2006-04-05 11:22:41,043 [1816] INFO NHibernate.Impl.SessionFactoryImpl [(null)] - building session factory
'aspnet_wp.exe' (Managed): Loaded 'tbtlqaut', No symbols loaded.
NHibernate.Impl.SessionFactoryObjectFactory: 2006-04-05 11:22:41,215 [1816] INFO NHibernate.Impl.SessionFactoryObjectFactory [(null)] - no name configured
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,215 [1816] INFO NHibernate.Cfg.Configuration [(null)] - Searching for mapped documents in assembly: AecOceansoft.Domain
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,215 [1816] INFO NHibernate.Cfg.Configuration [(null)] - Found mapping documents in assembly: AecOceansoft.Domain.Employee.hbm.xml
NHibernate.Dialect.Dialect: 2006-04-05 11:22:41,230 [1816] INFO NHibernate.Dialect.Dialect [(null)] - Using dialect: NHibernate.Dialect.MsSql2000Dialect
NHibernate.Cfg.Binder: 2006-04-05 11:22:41,230 [1816] INFO NHibernate.Cfg.Binder [(null)] - Mapping class: AecOceansoft.Domain.Employee -> Employee
Spring.Data.Orm.NHibernate.LocalSessionFactoryObje ct: 2006-04-05 11:22:41,230 [1816] INFO Spring.Data.Orm.NHibernate.LocalSessionFactoryObje ct [(null)] - Building new Hibernate SessionFactory
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,230 [1816] INFO NHibernate.Cfg.Configuration [(null)] - processing one-to-many association mappings
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,230 [1816] INFO NHibernate.Cfg.Configuration [(null)] - processing one-to-one association property references
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,230 [1816] INFO NHibernate.Cfg.Configuration [(null)] - processing foreign key constraints
NHibernate.Dialect.Dialect: 2006-04-05 11:22:41,230 [1816] INFO NHibernate.Dialect.Dialect [(null)] - Using dialect: NHibernate.Dialect.MsSql2000Dialect
NHibernate.Cfg.SettingsFactory: 2006-04-05 11:22:41,230 [1816] INFO NHibernate.Cfg.SettingsFactory [(null)] - use outer join fetching: True
NHibernate.Connection.ConnectionProviderFactory: 2006-04-05 11:22:41,230 [1816] INFO NHibernate.Connection.ConnectionProviderFactory [(null)] - Intitializing connection provider: NHibernate.Connection.DriverConnectionProvider
NHibernate.Connection.ConnectionProvider: 2006-04-05 11:22:41,230 [1816] INFO NHibernate.Connection.ConnectionProvider [(null)] - Configuring ConnectionProvider
NHibernate.Cfg.SettingsFactory: 2006-04-05 11:22:41,246 [1816] INFO NHibernate.Cfg.SettingsFactory [(null)] - Optimize cache for minimal puts: False
NHibernate.Cfg.SettingsFactory: 2006-04-05 11:22:41,246 [1816] INFO NHibernate.Cfg.SettingsFactory [(null)] - Query language substitutions: {}
NHibernate.Cfg.SettingsFactory: 2006-04-05 11:22:41,246 [1816] INFO NHibernate.Cfg.SettingsFactory [(null)] - cache provider: NHibernate.Cache.HashtableCacheProvider
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,246 [1816] INFO NHibernate.Cfg.Configuration [(null)] - instantiating and configuring caches
NHibernate.Impl.SessionFactoryImpl: 2006-04-05 11:22:41,246 [1816] INFO NHibernate.Impl.SessionFactoryImpl [(null)] - building session factory
'aspnet_wp.exe' (Managed): Loaded 'skmmgq9w', No symbols loaded.
NHibernate.Impl.SessionFactoryObjectFactory: 2006-04-05 11:22:41,558 [1816] INFO NHibernate.Impl.SessionFactoryObjectFactory [(null)] - no name configured
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,558 [1816] INFO NHibernate.Cfg.Configuration [(null)] - Searching for mapped documents in assembly: AecOceansoft.Domain
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,558 [1816] INFO NHibernate.Cfg.Configuration [(null)] - Found mapping documents in assembly: AecOceansoft.Domain.Employee.hbm.xml
NHibernate.Dialect.Dialect: 2006-04-05 11:22:41,574 [1816] INFO NHibernate.Dialect.Dialect [(null)] - Using dialect: NHibernate.Dialect.MsSql2000Dialect
NHibernate.Cfg.Binder: 2006-04-05 11:22:41,574 [1816] INFO NHibernate.Cfg.Binder [(null)] - Mapping class: AecOceansoft.Domain.Employee -> Employee
Spring.Data.Orm.NHibernate.LocalSessionFactoryObje ct: 2006-04-05 11:22:41,574 [1816] INFO Spring.Data.Orm.NHibernate.LocalSessionFactoryObje ct [(null)] - Building new Hibernate SessionFactory
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,574 [1816] INFO NHibernate.Cfg.Configuration [(null)] - processing one-to-many association mappings
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,574 [1816] INFO NHibernate.Cfg.Configuration [(null)] - processing one-to-one association property references
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,574 [1816] INFO NHibernate.Cfg.Configuration [(null)] - processing foreign key constraints
NHibernate.Dialect.Dialect: 2006-04-05 11:22:41,590 [1816] INFO NHibernate.Dialect.Dialect [(null)] - Using dialect: NHibernate.Dialect.MsSql2000Dialect
NHibernate.Cfg.SettingsFactory: 2006-04-05 11:22:41,590 [1816] INFO NHibernate.Cfg.SettingsFactory [(null)] - use outer join fetching: True
NHibernate.Connection.ConnectionProviderFactory: 2006-04-05 11:22:41,590 [1816] INFO NHibernate.Connection.ConnectionProviderFactory [(null)] - Intitializing connection provider: NHibernate.Connection.DriverConnectionProvider
NHibernate.Connection.ConnectionProvider: 2006-04-05 11:22:41,590 [1816] INFO NHibernate.Connection.ConnectionProvider [(null)] - Configuring ConnectionProvider
NHibernate.Cfg.SettingsFactory: 2006-04-05 11:22:41,590 [1816] INFO NHibernate.Cfg.SettingsFactory [(null)] - Optimize cache for minimal puts: False
NHibernate.Cfg.SettingsFactory: 2006-04-05 11:22:41,590 [1816] INFO NHibernate.Cfg.SettingsFactory [(null)] - Query language substitutions: {}
NHibernate.Cfg.SettingsFactory: 2006-04-05 11:22:41,590 [1816] INFO NHibernate.Cfg.SettingsFactory [(null)] - cache provider: NHibernate.Cache.HashtableCacheProvider
NHibernate.Cfg.Configuration: 2006-04-05 11:22:41,590 [1816] INFO NHibernate.Cfg.Configuration [(null)] - instantiating and configuring caches
NHibernate.Impl.SessionFactoryImpl: 2006-04-05 11:22:41,590 [1816] INFO NHibernate.Impl.SessionFactoryImpl [(null)] - building session factory
'aspnet_wp.exe' (Managed): Loaded 'hr7j6y5p', No symbols loaded.

I thought all erros due to Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxy Creator, but i don't know how to solve it, can anyone help me about the erros above?

thanks a lot,

Jason Yu

Mark Pollack
10-24-2006, 08:41 PM
didn't see this post...will investigate....

sreenivask
11-11-2006, 02:23 PM
I got bitten by the same thing today. Then I discovered that I am calling ContextRegistry.GetContext() in one of the classes declared as a service.
Example:


public class Service
{
IApplicationContext ctx = ContextRegistry.GetContext()
Foo foo = null;
}

It was declared as a service like this:

<object id="Service" type="XXX.YYY.Service, ServiceAssembly">
<property name="foo" ref="Bar" />
</object>

In the unit test fixture I called the GetContext() method again and I noticed
that it went into a loop exactly on that spot in the test. After I found and removed the GetContext() call inside the Service class, the problem got fixed.

Mark Pollack
11-11-2006, 03:56 PM
Hi,
I've created a JIRA (http://opensource.atlassian.com/projects/spring/browse/SPRNET-394)issue. BTW, you can also get a ref to the IApplicationContext in your Service class by implementing IApplicationContextAware (http://www.springframework.net/doc-latest/reference/html/objects.html#objects-context-applicationcontextaware).



Any reason you are not using DI to wire up your service class?

Thanks for the feedback - it is greatly appreciated!

Mark

sreenivask
11-11-2006, 06:54 PM
Any reason you are not using DI to wire up your service class?


All our services are invoked through Microsoft WCF (or at least that is what the design is!). Therefore, I thought, they cannot be proxied by Spring. My plan is to create DAO objects that use HibernateTemplate and call them through IApplicationContext in the service layer.

After testing this scenario I rolled back the code and left this call to GetContext() in the service class by mistake. Tough one to catch: took a night's sleep to figure it out :-)

Thanks for the pointer to "IApplicationContextAware" attribute.

Sreenivas

Mark Pollack
09-07-2007, 04:08 AM
Hi,
The circular ref issue is resolved now, let us know if you still have problems.
Cheers,
Mark