'MyBatis does not provide column name for DB2 error SQLCODE=-407, SQLSTATE=23502

I am using MyBatis for inserting data in DB2. One of the Not-null columns was provided null and as a result Insert failed. However, the error message is not very useful. It shows many error codes but nothing that will help me zero in on the problem. Below is the relevant section from the exception.

        org.springframework.dao.DataIntegrityViolationException: 
        ### Error updating database.  Cause: com.ibm.db2.jcc.am.SqlIntegrityConstraintViolationException: DB2 SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC= , DRIVER=4.28.11
        ### The error may exist in class path resource [mybatis/my-mapper.xml]
        ### The error may involve com.searshc.hs.subscription.generator.mapper.MembershipMapper.insertMembership-Inline
        ### The error occurred while setting parameters
        ### SQL: INSERT INTO DB2SP.MDR_DTL(       MBR_ID_NO, CUS_NO, SBP_ID_NO, REN_PRD, REN_PRD_TYP_CD, SCK_NO, MBR_PRO_CD, CRT_SYS_CD, CRT_ID_CD, CRT_ID_LOCN_NO, LST_UPD_SYS_CD,LST_UPD_ID_CD   ) VALUES (      ?, ?, ?, ?, ?,      ?, ?, ?, ?, ?, ?,      ? );
        ### Cause: com.ibm.db2.jcc.am.SqlIntegrityConstraintViolationException: DB2 SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC= , DRIVER=4.28.11
        ; DB2 SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC= , DRIVER=4.28.11; nested exception is com.ibm.db2.jcc.am.SqlIntegrityConstraintViolationException: DB2 SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC= , DRIVER=4.28.11
            at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:251)
            at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70)
            at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:91)
            at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)

Stacktrace in Eclipse, does not show exact cause with column name

I created the complete query and run it via another tool (Dbeaver in this case), and this time i was able to see the correct error.

Error message shows correct column name in Dbeaver

Exception stacktrace in Dbeaver

Is there a way to get this level of detailed error message from MyBatis?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source