You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by "Thompson, Kent" <KT...@BrwnCald.com> on 2005/03/29 18:51:03 UTC

Boolean properties with Microsoft OracleClient

I'm using the Microsoft OracleClient (version is 1.0.5000.0) with IBatis
DataMapper 1.0.1.321.  I've have a couple of boolean properties in my
classes and am having some problems. 

First off, not exactly sure what type the column should be in the
database.  Secondly, I'm getting an 'NotSupportedException' from the
OracleClient when the TypeMapper is calling 'GetBoolean'....

Unhandled Exception: System.NotSupportedException: Specified method is
not supported.
   at System.Data.OracleClient.OracleDataReader.GetBoolean(Int32 i)
   at
IBatisNet.DataMapper.TypesHandler.BooleanTypeHandler.GetValueByName(Resu
ltProperty mapping, IDataReader dataReader)
   at
IBatisNet.DataMapper.TypesHandler.BaseTypeHandler.GetDataBaseValue(Resul
tProperty mapping, IDataReader dataReader)
   at
IBatisNet.DataMapper.MappedStatements.MappedStatement.SetObjectProperty(
ResultMap resultMap, ResultProperty mapping, Object& target, IDataReader
reader)
   at
IBatisNet.DataMapper.MappedStatements.MappedStatement.ApplyResultMap(Req
uestScope request, IDataReader reader, Object resultObject)
   at
IBatisNet.DataMapper.MappedStatements.MappedStatement.RunQueryForObject(
RequestScope request, IDalSession session, Object parameterObject,
Object resultObject)
   at
IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteQueryForObj
ect(IDalSession session, Object parameterObject, Object resultObject)
   at
IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteQueryForObj
ect(IDalSession session, Object parameterObject)
   at IBatisNet.DataMapper.SqlMapper.QueryForObject(String
statementName, Object parameterObject)

Has anybody dealt with this problem before?

Thanks.


Re: Boolean properties with Microsoft OracleClient

Posted by Roberto Rabe <ro...@apache.org>.
Yes, there are known issues with GetBoolean and GetByte with the
OracleClient provider (not supported).

This is not a clean workaround, but you could create a 2nd set of property
accessors in your class that is used by the mapper that actually sets the
class bool field just to get it working.

For example, the iBATIS NUnit tests use a class with a Guid property but
the tests store it in a varchar field in Oracle.  To make the test pass,
this is used (not great but it works with the provider and works on the
same class' private field _guid):

public Guid Guid
{
	get
	{
		return _guid;
	}
	set
	{
		_guid = value;
	}
}

public string GuidString {
	get {
		return _guid.ToString();
	}
	set {
		if (value == null) {
			_guid = Guid.Empty;
		}
		else {
			_guid = new Guid(value.ToString());
		}
	}
}

Probably could poke holes in there like String.Empty but I dan't think the
DataMapper passes that back as a result currently.  :-)

Hope this helps!

Roberto



On Tue, March 29, 2005 12:02, Pablo Lopez said:
> Hi Kent,
>
> I also had some problems with booleans with PostgreSQL. This was my
> email and my problem:
>
>> Hi everybody,
>>
>> I'm using iBatis under .NET and PostgreSQL (ODBC driver). I'm trying my
>> first mappings and I have a problem with the boolean datatype.
>>
>> Integer mapping is working okay, and I can query / insert objects
>> without any trouble, but the problem arises when one of the attributes
>> is a boolean (bool under .NET / bool under PostgreSQL).
>>
>> When I insert an object there is no problem, but when I query the
>> database to populate an object, the following exception arises:
>>
>> "Uncontrolled Exception: System.InvalidCastException: "Specified
>> conversion is not valid" (at
>> System.Data.Odbc.OdbcDataReader.GetBoolean(Int32 i)
>>
>>
>> I don't know what the problem is, cause I'm using bool types under .Net
>> and under PostgreSQL. I also tried the bit type (in the documentation),
>> but it doesn't work.
>>
>> What annoys me is that insertions are correct, but queries are not.
>
> I tried several solutions (specifying a dbtype = 'bool' in the resultMap
> property, for example) but none of them worked, so now I'm using shorts
> even it's still spring ;) (bad joke)
>
> Talking seriously, I know using a short type instead is messy and not
> elegant, in fact it annoys me quite a lot, but it's the only one that
> did work.
>
> I hope you're luckier. Just keep in touch if you come across something.
>
> See you,
>
> Pablo.
>
>
>


Re: Boolean properties with Microsoft OracleClient

Posted by Pablo Lopez <pl...@tecisa74.com>.
Hi Kent,

I also had some problems with booleans with PostgreSQL. This was my 
email and my problem:

> Hi everybody,
> 
> I'm using iBatis under .NET and PostgreSQL (ODBC driver). I'm trying my first mappings and I have a problem with the boolean datatype.
> 
> Integer mapping is working okay, and I can query / insert objects without any trouble, but the problem arises when one of the attributes is a boolean (bool under .NET / bool under PostgreSQL).
> 
> When I insert an object there is no problem, but when I query the database to populate an object, the following exception arises:
> 
> "Uncontrolled Exception: System.InvalidCastException: "Specified conversion is not valid" (at System.Data.Odbc.OdbcDataReader.GetBoolean(Int32 i)
> 
> 
> I don't know what the problem is, cause I'm using bool types under .Net and under PostgreSQL. I also tried the bit type (in the documentation), but it doesn't work.
> 
> What annoys me is that insertions are correct, but queries are not.

I tried several solutions (specifying a dbtype = 'bool' in the resultMap 
property, for example) but none of them worked, so now I'm using shorts 
even it's still spring ;) (bad joke)

Talking seriously, I know using a short type instead is messy and not 
elegant, in fact it annoys me quite a lot, but it's the only one that 
did work.

I hope you're luckier. Just keep in touch if you come across something.

See you,

Pablo.