-
Using abstract definitions to shorten xml configuration
Hi,
I want to use the possibility to define my xml file shorter by using the abstract object definitions.
I'm using spring 1.0.2 and the integration with NHibernate. The Dao object here all extend from HibernateSupportDao
When I use the following xml configuration, I get an NHibernate Exception specifyin that it could not find the connection string setting.
<objects xmlns="http://www.springframework.net">
<object id="NVNInsuranceProductDatabasePublisher" parent="InsuranceProductDatabasePublisher">
<property name="ValidLanguages" value="nl-NL"/>
<property name="InsuranceDao.SessionFactory.DbProvider" ref="ProductDatabaseNVNDbProvider"/>
</object>
<object id="NVBInsuranceProductDatabasePublisher" parent="InsuranceProductDatabasePublisher">
<property name="ValidLanguages" value="nl-BE, fr-BE"/>
<property name="InsuranceDao.SessionFactory.DbProvider" ref="ProductDatabaseNVBDbProvider" />
</object>
<object id="InsuranceProductDatabasePublisher" type="ThomasCook.Ecom.ProductDatabase.Publish.Publ ishers.Insurances.ProductDatabaseInsurancePublishe r, ThomasCook.Ecom.ProductDatabase" abstract="true">
<property name="LanguagePropertyExpression" value="Language"/>
<property name="InsuranceDao">
<object type="ThomasCook.Ecom.ProductDatabase.Publish.Dao. Implementations.InsuranceDao, ThomasCook.Ecom.ProductDatabase">
<property name="SessionFactory">
<object parent="ProductDatabaseSessionFactory"/>
</property>
</object>
</property>
</object>
<object id="ProductDatabaseSessionFactory" type="Spring.Data.Orm.NHibernate.LocalSessionFacto ryObject, Spring.Data.Orm.NHibernate" abstract="true" >
<property name="DbProvider">
<null/>
</property>
<!--Must be overridden by all concretes -->
<property name="MappingAssemblies">
<list>
<value>ThomasCook.Ecom.ProductDatabase</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvi der" />
<entry key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
<entry key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<entry key="hibernate.show_sql" value="false" />
</dictionary>
</property>
</object>
<object id="ProductDatabaseNVBDbProvider" type="Spring.Data.Support.SqlProvider, Spring.Data">
<property name="ConnectionString" value="${connection.NVBProductDatabaseDb}" />
</object>
<object id="ProductDatabaseNVNDbProvider" type="Spring.Data.Support.SqlProvider, Spring.Data">
<property name="ConnectionString" value="${connection.NVNProductDatabaseDb}" />
</object>
</objects>
When I change the definition of the definition of the ProductDatabaseSessionFactory object not to include a null for the DbProvider property but a filled in value (eg a ref to ProductDatabaseNVNDbProvider), then I get an InvalidPropertyException "DbProvider" node can not be resolved for the specified root context.
Maybe this is something specific for the NHibertnate integration, since I have used this same setup in other places without any problem.
What are my alternatives here.
KR
Patrick
-
Have you tried completely removing DbProvider property from the ProductDatabaseSessionFactory definiton? Not sure why you would have it in the abstract definition...
Also, I'm assuming that you have PropertyPlaceholderConfigurer defined, even though it is not shown in the sample...
- Aleks
-
Aleks,
I have tried all that.
I'm also one step closer to the reason why it does not work. The DbProvider property is part of the Spring.Data.Orm.NHibernate.LocalSessionFactoryObje ct. This SessionFactoryObject creates NHibernate ISession objects. On these objects DBProvider is unknown. That explains the error when I want to overwrite (or initially assign) the DBProvider property.
Another thing what I have tried to do, is to define an Abstract ProductDatabaseDAO without the SessionFactory property. In the different publishers I would then assign the SessionFactory property. This gives an exception that there must be either a HibernateTemplate or a SessionFactory specified.
This comes from the fact that the HibernateDaoSupport (the superclass of all the DAO's) extends the DaoSupport which implement the AfterPropertiesSet method (part of the IInitializingObject interface). In this method there is check to see if there is a SessionFactory set.
This is not the case, because this one would be set by the publisher (using the InsuranceDao.SessionFactory property) and as such I get an exception.
Put in other words. I'm looking for a way that allows me to define abstract definitions for objects that have the AfterPropertiesSet method.
When this method contains a check for the presence of a property it seems impossible to define an abstract definition that does not contain this property.
Is there a work around for this?
Patrick
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules