PDA

View Full Version : ibatis using Spring.NET



puow
11-17-2009, 02:15 PM
I'm using Spring.NET and am happy that I've got this working fine. I'm now trying to get iBatis to work. On the whole I think I've managed something that looks right in principal but I've hit a stumbling block with the following exception:



[NullReferenceException: Object reference not set to an instance of an object.]
IBatisNet.DataMapper.Configuration.DomSqlMapBuilde r.ConfigureSqlMap() +1003
IBatisNet.DataMapper.Configuration.DomSqlMapBuilde r.Initialize() +5535
IBatisNet.DataMapper.Configuration.DomSqlMapBuilde r.Build(XmlDocument document, DataSource dataSource, Boolean useConfigFileWatcher, Boolean isCallFromDao) +384

[ConfigurationException:
- The error occurred while loading SqlMap.
- The error occurred in <sqlMap resource="Models/Dao/ibatis/User.xml" xmlns="http://ibatis.apache.org/dataMapper" />.]
IBatisNet.DataMapper.Configuration.DomSqlMapBuilde r.Build(XmlDocument document, DataSource dataSource, Boolean useConfigFileWatcher, Boolean isCallFromDao) +483
IBatisNet.DataMapper.Configuration.DomSqlMapBuilde r.Build(XmlDocument document, Boolean useConfigFileWatcher) +46
IBatisNet.DataMapper.Configuration.DomSqlMapBuilde r.Configure(String resource) +125

[ObjectDefinitionStoreException: Factory method 'IBatisNet.DataMapper.ISqlMapper Configure(System.String)' threw an Exception.]
Spring.Objects.Factory.Support.SimpleInstantiation Strategy.Instantiate(RootObjectDefinition definition, String name, IObjectFactory factory, MethodInfo factoryMethod, Object[] arguments) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\S upport\SimpleInstantiationStrategy.cs:216
Spring.Objects.Factory.Support.ConstructorResolver .InstantiateUsingFactoryMethod(String name, RootObjectDefinition definition, Object[] arguments) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\S upport\ConstructorResolver.cs:339
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.InstantiateUsingFactoryMethod(St ring name, RootObjectDefinition definition, Object[] arguments) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\S upport\AbstractAutowireCapableObjectFactory.cs:106 2
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObjectInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\S upport\AbstractAutowireCapableObjectFactory.cs:944
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\S upport\AbstractAutowireCapableObjectFactory.cs:862

[ObjectCreationException: Error creating object with name 'sqlMapper' defined in 'file [C:\dotNet\SpringMVCExample\ExampleApplication\Conf ig\Controllers.xml] line 12' : Initialization of object failed : Factory method 'IBatisNet.DataMapper.ISqlMapper Configure(System.String)' threw an Exception.]

....



I have a User.xml sqlMap:



<?xml version="1.0" encoding="utf-8" ?>
<sqlMap>
<typeAlias alias="User" assembly="ExampleApplication" type="ExampleApplication.Models.Entity.User" />

<resultMap id="SelectAllResult" class="User">
<result property="Id" column="id" />
<result property="Name" column="name" />
<result property="CreatedBy" column="createdBy" />
<result property="ModfiiedBy" column="modifiedBy" />
<result property="CreatedOn" column="createdOn" />
<result property="ModifiedOn" column="modifiedOn" />
</resultMap>

<select id="SelectAll" resultMap="SelectAllResult">
select id,
name,
createdBy,
modifiedBy,
createdOn,
modifiedOn
from USERS
</select>
</sqlMap>


As well as the UserDao and iBatisDao object:



public class IbatisDao
{
private ISqlMapper sqlMap;

public ISqlMapper SqlMap
{
get { return sqlMap; }
set { sqlMap = value; }
}

}

public class UserDao : IbatisDao, IUserDao
{
public List<User> selectAll()
{
return (List<User>)SqlMap.QueryForList("SelectAll",null);
}
}



Now I'm trying to get Spring to create the ISqlMapper object and this is where I'm hitting the exception: This is the Controllers.xml file mentioned in the error trace.



<object id="builder"
type="IBatisNet.DataMapper.Configuration.DomSqlMapBuilde r, IBatisNet.DataMapper"
singleton="true"/>

<object id="sqlMapper"
type="IBatisNet.DataMapper.ISqlMapper, IBatisNet.DataMapper"
factory-method="Configure"
factory-object="builder"
singleton="true">
<constructor-arg value="Config/sqlMap.config.xml"/>
</object>


I want the sqlMap.config file in the Config directory hence the call to Configure instead of Instance(): N.B. if I place the sqlMap.config file in the root of the project and use the Instance() method I get exactly the same error.

For completeness here is said file which does get parsed as if I mess about with it I can produce errors like file not found etc.



<?xml version="1.0" encoding="utf-8"?>
<sqlMapConfig
xmlns="http://ibatis.apache.org/dataMapper"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

<settings>
<setting useStatementNamespaces="false"/>
<setting cacheModelsEnabled="false"/>
</settings>


<providers resource="Config/providers.config.xml"/>

<database>
<provider name="sqlServer1.1"/>
<dataSource name="Scratch"
connectionString="Data Source=XXXX;Initial Catalog=Scratch;User ID=XXXX;Password=XXXX;database=XXXX"/>
</database>

<sqlMaps>
<sqlMap resource="Models/Dao/ibatis/User.xml"/>
</sqlMaps>

</sqlMapConfig>


Let me know if there's something relevant I've failed to post. I presume that there is a null reference somewhere but I don't know how to find out what is missing. any pointers would be greatfully received.