0

I have an object that has a variable that's a List like so:

ExportQueue.java

public class ExportQueue implements Serializable {
    private List<String> errors;

    public List<String> getErrors() {
        return errors;
    }

    public void setErrors(List<String> errors) {
        this.errors = errors;
    }
    public void addError(String error) {
        if(this.errors == null) this.errors = new ArrayList<String>();
        this.errors.add(error);
    }
}

I've defined the ResultMap for this...

ExportQueueDao.xml

<mapper namespace="...">
    <resultMap id="exportQueueResultMap" type="...ExportQueue">
         <result property="errors" column="errors"
            typeHandler="...CommaSeparatedStringListTypeHandler" />
    </resultMap>
</mapper>

ExportQueueDao.java

@Insert(INSERT_UPDATE)
@Options(useGeneratedKeys = true, keyProperty = "id")
int insertOrUpdate(ExportQueue ExportQueue);

I have a CommaSeparatedStringListTypeHandler defined but I'm getting an error when I try to INSERT the object. As far as I understand INSERT doesn't use the ResultMap and therefore doesn't see the TypeHander so it doesn't know what to do with the List errors.

This is the error I get with the current set up...

Caused by: org.apache.ibatis.executor.ExecutorException: There was no TypeHandler found for parameter errors of statement ....dao.ExportQueueDao.insertOrUpdate

How do I configure this so MyBatis knows what to do with the List<String> errors?

Michał Rybak
  • 8,648
  • 3
  • 42
  • 54
kasdega
  • 18,396
  • 12
  • 45
  • 89
  • @kasdegaCan you do any operation with this result map, i mean any operation can success with this result map or all is failed. I think you missing some expression, can you put the full map.xml or this one is full map.xml? – erhun Feb 07 '13 at 22:53
  • the rest of the dao.xml file is rather uneventful, I've purposefully left it out for brevity sake, and yes it works fine if I remove the errors column altogether. – kasdega Feb 07 '13 at 22:57
  • you try to define a custome type handler, so where is your CommaSeparatedStringListTypeHandler class implementation? – erhun Feb 07 '13 at 23:08
  • Its on the classpath, we're using it for other SELECTS in other spots but never for an insert. I think you're missing the point (or maybe I am) the error that we get is saying that it doesn't know what TypeHandler to even try for 'errors' not that it couldn't find the class or had an error in the class. I'll post the error in a second. – kasdega Feb 07 '13 at 23:34
  • Should you post your implementation about TypeHandler? – Vargan Feb 08 '13 at 23:57

1 Answers1

1

You can define in your myBatis-config to use CommaSeparatedStringListTypeHandler as a default handle for the type List

Once you define this , you wont have to specially mention in the result map the typeHandler for "errors" also while inserting MyBatis will by default use CommaSeparatedStringListTypeHandler for your errors.

<typeHandlers> 
        <typeHandler javaType='List' handler='CommaSeparatedStringListTypeHandler' /> 
</typeHandlers>
faizan
  • 680
  • 1
  • 6
  • 15