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 Kim Goings <ki...@levelfivesolutions.com> on 2006/02/06 18:49:24 UTC

CustomTypeHandler ?

I have a db schema using the Single Table Inheritence pattern.  (One table,
each row "becomes" a different type.)  

I wrote a CustomTypeHandler and used the getResult method to translate it
into the correct type of object.  That works great.  

However, because I am using a "global" typeHandler definition like: 

<typeHandler javaType="foo.Question" callback="foo.QuestionTypeHandler"/ >
	
the custom type handler's setParameter method also is invoked when the type
is used as the parameter to an insert or update statement.  I'd hoped that I
could just set the object as the parameter and then use dot notation in the
parameter list to grab the fields from the object, but it looks like
setParameter assumes a single, non-complex parameter in the statement.  

eg:  

public void setParameter(ParameterSetter setter, Object parameter) throws
SQLException {
      setter.setObject(parameter);
}

<insert id="insert"
	parameterClass="question" >
	INSERT INTO question (typeId, text, categoryId, sequence)
		VALUES (#question.typeId#, #question.questionText#,
#question.categoryId#, #question.sequence#)
	<selectKey resultClass="int" keyProperty="id">
   		SELECT LAST_INSERT_ID() AS id
 	</selectKey>
</insert>


Am I going about this all wrong?  Should I be using a row handler instead?  

Thanks,
Kim