View Full Version : Error using DBProvider ?!?
Hi,
i'm trying to use Spring with Hibernate and MySQL. Now i've got a big problem with the dbProvider.
My configuration file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:db="http://www.springframework.net/database">
<object id="person" type="MovieSpringApp.Domain.Person, MovieSpringApp"/>
<object id="personService" type="MovieSpringApp.Services.PersonService, MovieSpringApp">
<!--<property name="PersonDAO" ref="personDAO"/>-->
</object>
<object id="personDAO" type="MovieSpringApp.DAO.PersonDAO, MovieSpringApp">
<!--<property name="SessionFactory" ref="sessionFactory"/>-->
</object>
<db:dbProvider id="dbProvider"
provider="NHibernate.Driver.MySqlDataDriver"
connectionString="Server=localhost;Database=test;User ID=root;Password=linux;"/>
...
By Running the project occurs the exception (innerexception):
2007-04-03 10:36:37,421 DEBUG Program - 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: XmlException parsing XML document from file [N:\develop\Test\Spring_Movie\MovieSpringApp\MovieS pringApp\bin\Debug\config\applicationcontext.xml] ---> System.Xml.XmlException: The 'http://www.springframework.net/database:dbProvider' element is not declared. ---> System.Xml.Schema.XmlSchemaValidationException: The 'http://www.springframework.net/database:dbProvider' element is not declared.
--- End of inner exception stack trace ---
...
Could somebody help me, solving the problem???
And: Is there an tutorial of using Spring with MySQL and Hibernate ?
Thanks a lot,
winx
boriska
04-03-2007, 12:27 PM
Hello, did you try to configure
<spring>
<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>
?
Hi,
just tried, the error message looks like this:
2007-04-03 13:47:37,328 DEBUG Program - Configuration system failed to initialize
2007-04-03 13:47:37,359 DEBUG Program - at System.Configuration.ConfigurationManager.GetSecti on(String sectionName)
at Spring.Util.ConfigurationUtils.GetSection(String sectionName) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Util\ConfigurationUtils.cs:line 59
at Spring.Context.Support.ContextRegistry.InitializeC ontextIfNeeded() in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Context\Support\ContextRegistry.cs:line 266
at Spring.Context.Support.ContextRegistry.GetContext( ) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Context\Support\ContextRegistry.cs:line 166
at MovieSpringApp.Program.Main(String[] args) in N:\develop\Test\Spring_Movie\MovieSpringApp\MovieS pringApp\Program.cs:line 26
2007-04-03 13:47:37,359 DEBUG Program -
2007-04-03 13:47:37,359 DEBUG Program - System.Configuration.ConfigurationErrorsException: Unrecognized configuration section spring/parsers. (N:\develop\Test\Spring_Movie\MovieSpringApp\Movie SpringApp\bin\Debug\MovieSpringApp.vshost.exe.conf ig line 16)
at System.Configuration.ConfigurationSchemaErrors.Thr owIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.Throw IfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.Throw IfInitErrors()
at System.Configuration.ClientConfigurationSystem.Ens ureInit(String configKey)
Another try was coping the spring-database.xsd in My VS XML Schemas Directory... but the exception after this (not using the parser in the app.config) looks like this:
2007-04-03 13:51:15,328 DEBUG Program -
2007-04-03 13:51:15,328 DEBUG Program - 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: XmlException parsing XML document from file [N:\develop\Test\Spring_Movie\MovieSpringApp\MovieS pringApp\bin\Debug\config\applicationcontext.xml] ---> System.Xml.XmlException: The 'http://www.springframework.net/database:dbProvider' element is not declared. ---> System.Xml.Schema.XmlSchemaValidationException: The 'http://www.springframework.net/database:dbProvider' element is not declared.
something is always going wrong...i've been trying to establish one single connection to my db since 2 days...but it don't work
--- End of inner exception stack trace ---
boriska
04-03-2007, 01:00 PM
I looked into my web.config, so I also found :
<configuration>
<configSections>
<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>
Just look into Chapter 16. DbProvider( Reference Documentation) ...there is a sample over there
....
<configuration>
thanks!!!
ok that's it :)
Another question. Could you also help me confihuring my sessionFactory using hibernate:
<object id="sessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate">
<property name="dbProvider" ref="dbProvider"/>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="hibernate.dialect" value="NHibernate.Dialect.MySQLDialect"/>
<entry key="hibernate.connection.driver_class" value="NHibernate.Driver.MySqlDataDriver"/>
</dictionary>
</property>
<property name="MappingAssemblies">
<list>
<value>MovieSpringApp</value>
</list>
</property>
</object>
boriska
04-03-2007, 01:09 PM
Try to check Spring.Data.NHibernate12-20070329-1141.zip or Spring.Data.NHibernate-20070330-0103
in the nightly builds. You can find a Spring.Northwind sample. I think that is what you need...
Mark Pollack
04-03-2007, 01:30 PM
Hi,
Thanks for your patience 'winx'. Just another reminder to work on the docs and better referal to the example app as a tutorial.
Cheers,
Mark
Hi Mark,
no problem :)
Thanks for your work... i'm new in Spring and don't nearly know what to do...but i'm doing my best to understand the Framework.
Do you have an exmaple of using Spring with nbhibernate and mysql... i can't find an example config-file which i could depend on in the northwind example.
Greets,
winx
steinard
04-03-2007, 02:09 PM
Hi!
The examples and the documentation describes what you need to do pretty well. In addition, I posted my working config a while ago, so if you like you can always take a look at it here (http://forum.springframework.net/showpost.php?p=5085&postcount=5).
I have changed my configuration slightly, according to refactorings I've done, but in principle, it's pretty much the same.
Cheers,
Steinar
Hi,
thanks, i've changed my configuration to this:
<object id="sessionFactoryRef" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate">
<property name="dbProvider" ref="dbProviderRef"/>
<property name="MappingAssemblies">
<list>
<value>MovieSpringApp</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="hibernate.dialect" value="NHibernate.Dialect.MySQLDialect"/>
<entry key="hibernate.connection.driver_class" value="NHibernate.Driver.MySqlDataDriver"/>
</dictionary>
</property>
</object>
...
but got another error again :mad:
2007-04-03 15:22:41,890 DEBUG Program - 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: Failed parsing object definition '<object id="sessionFactoryRef" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate" xmlns="http://www.springframework.net"><property name="dbProvider" ref="dbProviderRef" /><property name="MappingAssemblies"><list><value>MovieSpringApp</value></list></property><property name="HibernateProperties"><dictionary><entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" /><entry key="hibernate.dialect" value="NHibernate.Dialect.MySQLDialect" /><entry key="hibernate.connection.driver_class" value="NHibernate.Driver.MySqlDataDriver" /></dictionary></property></object>' ---> Spring.Objects.Factory.ObjectDefinitionStoreExcept ion: Error registering object with name 'sessionFactoryRef' defined in 'file [N:\develop\Test\Spring_Movie\MovieSpringApp\MovieS pringApp\bin\Debug\config\applicationcontext.xml]' : Object class [Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate] not found.
<object id="sessionFactoryRef" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate" xmlns="http://www.springframework.net"><property name="dbProvider" ref="dbProviderRef" /><property name="MappingAssemblies"><list><value>MovieSp... ---> System.TypeLoadException: Could not load type from string value 'Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate'.
at Spring.Util.TypeResolver.ResolveType(String typeName) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Util\TypeResolver.cs:line 156
at Spring.Util.TypeResolver.Resolve(String typeName) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Util\TypeResolver.cs:line 59
at Spring.Util.CachedTypeResolver.Resolve(String typeName) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Util\CachedTypeResolver.cs:line 103
at Spring.Objects.ObjectUtils.ResolveType(String typeName) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\ObjectUtils.cs:line 311
at Spring.Objects.Factory.Support.DefaultObjectDefini tionFactory.CreateObjectDefinition(String typeName, String parent, ConstructorArgumentValues arguments, MutablePropertyValues properties, AppDomain domain) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\DefaultObjectDefinitionF actory.cs:line 83
at Spring.Objects.Factory.Xml.DefaultXmlObjectDefinit ionParser.ParseObjectDefinition(XmlElement element, String id, XmlResourceReader parser) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Xml\DefaultXmlObjectDefinitionPa rser.cs:line 474
--- End of inner exception stack trace ---
do you have an idea?
boriska
04-03-2007, 04:33 PM
Have you added a reference to Spring.Data.NHibernate.dll to your project?
It looks like that the LocalSessionFactoryObject is not found in the dll.
Hi,
i've added bot nhibernate.dll and spring.data.nhibernate12.dll...
but it doesn't work...
if i try to generate an object in my source code Spring.Data.NHibernate.LocalSessionFactoryObject everything seems to be alright.
anybody an idea?
thanks
changed the
<object id="sessionFactoryRef" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate">
to
object id="sessionFactoryRef" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate12">
and now:
it's running :)
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.