1

I would like to insert a list of strings into a single column in my database using Mybatis. I've tried using a Custom TypeHandler but I can't even get Mybatis to invoke it.

For a more detailed report on what I've already done click here

Community
  • 1
  • 1
kasdega
  • 18,396
  • 12
  • 45
  • 89
  • have you read this http://www.mybatis.org/core/configuration.html#typeHandlers article? – maks Feb 19 '13 at 19:57
  • not specifically but I will, it looks like a good starting spot. I am somewhat familiar with TypeHandlers...my question is how to do get Mybatis to invoke the typehandler I need when doing an INSERT? – kasdega Feb 19 '13 at 20:03

1 Answers1

1

While specifying parameters for INSERT statement do like this:

INSERT INTO tableName(a) VALUES(#{aVal, typeHandler=com.test.YourTypeHandler})

where aVal is the parameter that you have passed to statement. Also intead of full name of typehandler you can use it alias. But don't forget to register it(typeHandler) in configuration file of MyBatis

edited

A good practise is specifying a type of value to be inserted like this: #{aVal, jdbcType=VARCHAR, typeHandler=com.test.YourTypeHandler}. It will save you from issues with null values of aVal

maks
  • 5,911
  • 17
  • 79
  • 123
  • I've asked this question three different ways on two different sites...you're the first to answer and your answer works perfectly. Thank you so much. If anyone reads this please mark this answer as useful, it is well deserved. This is what makes stackoverflow so great! – kasdega Feb 19 '13 at 22:44