MyBatis, Postgresql, Byte Array and ByteA

 

Spent about an hour or two trying to find the correct TypeHandler and jdbcType combination to be able to retrieve data from a bytea type column in a postgresql table.

 

This is what I got:

 jdbcType="BINARY" typeHandler="org.apache.ibatis.type.ByteArrayTypeHandler"

Hope this helps someone.

For inserting I used this combination:

javaType=byte[], jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler

The error I encountered was :

org.postgresql.util.PSQLException: Bad value for type int : \3

 

The error is caused by defaulting to the use of oid when the field was actually stored in the column and not elsewhere.

 

Comment if this was useful!