Hi all ibatis developers and lovers.
I'm spending some time to learn the pattern proposed with netpetshop +
ibatis mapper for developing a simple application of mine as I think
the best way to learn something is to try in real life applications.

This is my experience on debugging mapping files.
As a newbie I do some errors in configuration and I found that is
really difficult to debug as the framework is not so explicit and
talkative about the errors.
I have proposed a couple of fixes that can be discussed.

I'm using build 321

First problem:
The cause was simply "Object null reference"... not so explicit.

Line 75: catch(Exception e)
Line 76: {
Line 77: throw new ConfigurationException(string.Format("DaoManager
could not configure SqlMapDaoSessionHandler.Cause: {0}", e.Message));
Line 78: }
Line 79: }


Source File: 
C:\Dev\iBatis\iBatisNet-1.0.1.321\source\IBatisNet.DataAccess\DaoSessionHandlers\SqlMapDaoSessionHandler.cs
   Line: 77

Proposed fix:

catch(Exception e)
{
throw new ConfigurationException(string.Format("DaoManager could not
configure SqlMapDaoSessionHandler.Cause: {0}", e.Message), e);
}

Now I can jump to the line that raises the exception:

Line 448: XmlDocument config = Resources.GetAsXmlDocument(sqlMapNode);
Line 449:
Line 450: sqlMapName =
config.SelectSingleNode("sqlMap").Attributes["namespace"].Value;
Line 451:
Line 452: #region Load TypeAlias


Source File: 
C:\Dev\iBatis\iBatisNet-1.0.1.321\source\IBatisNet.DataMapper\Configuration\DomSqlMapBuilder.cs
   Line: 450

I changed this way:

XmlDocument config = Resources.GetAsXmlDocument(sqlMapNode);

if (config.SelectSingleNode("sqlMap") == null)
throw new NullReferenceException("Missing 'sqlMap' tag");
if (config.SelectSingleNode("sqlMap").Attributes["namespace"] == null)
throw new NullReferenceException("Missing 'namespace' attribute on
'sqlMap' tag");

sqlMapName = config.SelectSingleNode("sqlMap").Attributes["namespace"].Value;

so I fixed my map (namespace was missing).

then I found an error on my dao configuration ad I fixed.
Unfortunately seems that after a dao change I need to rebuild or
restert application to make it recognize the changed file.
Same for maps: the only way to reload is restart or rebuild (build is
not enough) the app.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error: 


Line 49: else
Line 50: {
Line 51: return dataReader.GetString(index);
Line 52: }
Line 53: }


Source File: 
C:\Dev\iBatis\iBatisNet-1.0.1.321\source\IBatisNet.DataMapper\TypesHandler\StringTypeHandler.cs
   Line: 51

Changed:

try
{
if (dataReader.IsDBNull(index) == true)
{
return System.DBNull.Value;
}
else
{
return dataReader.GetString(index);
}
}
catch(InvalidCastException icex)
{
throw new InvalidCastException(string.Format("Invalid cast converting
column '{0}'", mapping.ColumnName), icex);
}


so I was informed that I have missed a field on the output mapping.
I then fixed that and my application now runs.

now the debug is alittle more easy :)

any comment?


Manu

Reply via email to