ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kim Goings" <kim.goi...@levelfivesolutions.com>
Subject CustomTypeHandler ?
Date Mon, 06 Feb 2006 17:49:24 GMT

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

 




Mime
View raw message