You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Tom Duffey <td...@utilivisor.com> on 2006/10/17 01:48:24 UTC

Problem w/enum and TypeHandlerCallback

Hi All,

I'm having a problem with Java 5 Enums and iBATIS  
TypeHandlerCallbacks.  I've read the wiki article and it doesn't help  
with my particular issue.  Retrieving objects is working fine but  
inserting/updating them is throwing this NPE:

java.lang.NullPointerException
     at com.ibatis.sqlmap.engine.type.UnknownTypeHandler.setParameter 
(UnknownTypeHandler.java:72)
     at  
com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParamete 
r(BasicParameterMap.java:165)
     at  
com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParamete 
rs(BasicParameterMap.java:125)
     at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate 
(SqlExecutor.java:76)
     at  
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteUp 
date(GeneralStatement.java:200)
     at  
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdat 
e(GeneralStatement.java:78)
     at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert 
(SqlMapExecutorDelegate.java:446)
     at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert 
(SqlMapSessionImpl.java:82)
     at org.springframework.orm.ibatis.SqlMapClientTemplate 
$9.doInSqlMapClient(SqlMapClientTemplate.java:358)
     at org.springframework.orm.ibatis.SqlMapClientTemplate.execute 
(SqlMapClientTemplate.java:188)
     at org.springframework.orm.ibatis.SqlMapClientTemplate.insert 
(SqlMapClientTemplate.java:356)
     ...

Here's my basic setup:

public interface Tenant {
	public enum Type { FOO, BAR }
	public Type getType();
	public void setType(Type type);
	...
}
public class TenantImpl implements Tenant {
	private Type type;
	public Type getType() { return type; }
	public void setType(Type type) { this.type = type; }
	...
}

My type handler for Tenant$Type looks a lot like the examples in the  
wiki article.  The types are mapped in my SqlMapConfig:

<typeHandler javaType="foo.bar.Tenant$Type"  
callback="com.utilivisor.dao.ibatis.TenantTypeEnumTypeHandler"/>

I'm messing around with UnknownTypeHandler.setParameter() and am very  
confused.  I checked the incoming value of parameter.getClass() and  
it is correct, i.e., foo.bar.Tenant$Type.  usingJavaPre5 is set  
(Which is confusing by itself because I am using Java5) so  
getBaseClass() is  called and the new searchClass is foo.bar.Tenant.   
I do not have or want a type handler for foo.bar.Tenant.  Can anyone  
help?

Tom