MyBatis 3 | Need help in implementing custom TypeHandler
posted 5 years ago
I have a POJO object which has nullable fields and I need to persist the object in Oracle database (10g). I wrote an insert query to achieve this but soon ran into a problem
where I had to define the JDBC type for null fields. As per documentation I cannot make direct calls to setNull on the PreparedStatement object as I am using MyBatis configuration which directly maps objects to queries. Hence, I thought of writing a custom TypeHandler to solve the problem.
My insert query looks like this:
In the MapperConfig.xml file:
And for the ExampleTypeHandler I have implemented the methods:
- setParameter(PreparedStatement arg0, int arg1, Object arg2, JdbcType arg3)
- getResult(CallableStatement arg0, int arg1)
- getResult(ResultSet arg0, String arg1)
With this code/config I am getting a runtime error when the insert query is invoked:
SQL command not ended properly.
Could you please help me in getting this to work ? Not sure if I am missing something here. If you have any working example of TypeHandler please share it with me.
Note: The version of MyBatis I am using in my project is 3.0.4.