PDA

View Full Version : Missing SqlProvider from NHibernate Module?


mcantrell
02-12-2007, 10:55 PM
Please forgive me if I've overlooked something simple, I'm new to .NET and I'm following along from the example application from the NHibernate module. I've added references to all of the DLLs in its bin/2.0 dir (I wasn't exactly sure what all of the runtime dependencies were).

When I try to run my unit test, I get the following runtime error:


Class Initialization method SpringLunchAndLearnTest.HibernateInventoryDaoTest. MyClassInitialize threw exception. System.Configuration.ConfigurationErrorsException: System.Configuration.ConfigurationErrorsException: Error instantiating context 'spring.root'. ---> Spring.Objects.FatalObjectException: Cannot instantiate Type [Spring.Context.Support.XmlApplicationContext] using ctor [Void .ctor(System.String, Boolean, System.String[])] : 'Exception has been thrown by the target of an invocation.' ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Spring.Objects.Factory.ObjectDefinitionStoreExcept ion: Error registering object with name 'DbProvider' defined in 'file [C:\dev\workspace\vs\solutions\LunchAndLearn\trunk\ SpringLunchAndLearn\TestResults\MCantrell_LI-HC96K71 2007-02-12 15_40_16\Out\Dao.xml]' : Object class [Spring.Data.Support.SqlProvider, Spring.Data] not found.
<object id="DbProvider" type="Spring.Data.Support.SqlProvider, Spring.Data" xmlns="http://www.springframework.net"><property name="ConnectionString" value="${db.connectionString}" /></object> ---> System.TypeLoadException: Could not load type from string value 'Spring.Data.Support.SqlProvider, Spring.Data'. ---> System.TypeLoadException: Could not load type 'Spring.Data.Support.SqlProvider' from assembly 'Spring.Data, Version=1.1.0.2, Culture=neutral, PublicKeyToken=null'..



Keep in mind that all of my configuration code was pretty much cut and pasted from the Northwind example included with the NHibernate Spring module. I'm at a loss to explain the missing class from the assembly. Am I missing something?

Here's a peak at some of my code. Please let me know if you need me to post anything else.

InventoryDao.cs

using Spring.Data.NHibernate.Support;

namespace SpringLunchAndLearn
{
public interface IInventoryDao
{
Inventory getById(int inventoryId);
}

public class HibernateInventoryDao : HibernateDaoSupport, IInventoryDao
{
public Inventory getById(int inventoryId)
{
return (Inventory) HibernateTemplate.Load(typeof (Inventory), inventoryId);
}
}
}



Dao.xml

<object id="DbProvider" type="Spring.Data.Support.SqlProvider, Spring.Data">
<property name="ConnectionString" value="${db.connectionString}"/>
</object>


app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="databaseSettings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="parsers" type="Spring.Context.Support.ConfigParsersSectionHandler , Spring.Core" />
</sectionGroup>
</configSections>
<databaseSettings>
<add key="db.connectionString" value="Server=DBRPTSTG01;initial catalog=db_partnernet_2;Integrated Security=SSPI" />
</databaseSettings>
<spring>
<context>
<resource uri="Dao.xml"/>
</context>
<parsers>
<parser namespace="http://www.springframework.net/database"
type="Spring.Data.DatabaseConfigParser, Spring.Data"
schemaLocation="assembly://Spring.Data/Spring.Data/spring-database.xsd" />
</parsers>
</spring>
</configuration>

mcantrell
02-12-2007, 10:59 PM
I just found this while googling for the problem:

http://forum.springframework.net/archive/index.php/t-921.html

Looks like the test example is still out of date.

Erich Eichinger
02-13-2007, 02:01 AM
Hi,

as a quick help: you need to change the definition


<object id="DbProvider" type="Spring.Data.Support.SqlProvider, Spring.Data">
<property name="ConnectionString" value="${db.connectionString}"/>
</object>


with


<db:dbProvider id="DbProvider"
provider="SqlServer-1.1"
connectionString="@{database.connectionstring}"/>


and you should be done. You must not forget to add the xml namespace to your <objects> element:


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


cheers,
Erich

Mark Pollack
02-13-2007, 02:52 PM
Hi,

I don't know how it got out of date, my local checkout didn't even recognize those files as belonging to CVS for some reason. I've updated the config files, added configuration to use Common.Logging, updated the readme, and added an incredibly primitive Web project as a starting point for more development. The .dlls used are the debug .dlls from the latest Spring.NET nightly build. Get the latest build from the download page - I assume you are downloading the 1.0.2 version?

The test class FulfillmentServiceTests and in the project Spring.Northwind.IntegrationTests exercises the code a bit. For some reason the test that uses declarative tx configuration based on attribute declarations is not working, so use the other test method in the meantime until I sort that out.

Cheers,
Mark

mcantrell
02-14-2007, 03:07 PM
Thank you, I've got it all working now :)

Bruno Baia
02-14-2007, 09:24 PM
cool, +1 user :D

Bruno