title: Which Mybatis TypeHandler to use with object stored as bytea in PostgreSQL?
body: <p>I use Mybatis mapper to perform SQL query (Postgres) which returns some fields of bytea type. There are different object types stored within this fields and I encountered an error with deserialization.</p>
  
  <p>I have a mapper:</p>
  
  <pre><code>&lt;mapper namespace="WorkflowMapper"&gt;
      &lt;resultMap id="WorkflowResultMap" type="Workflow"&gt;
          &lt;id column="id" property="id" javaType="java.lang.String"/&gt;
          &lt;result property="amount" column="amount" javaType="java.lang.Float" jdbcType="BLOB"/&gt;
  &lt;/resultMap&gt;
  &lt;select id="findAllCustom" resultMap="WorkflowResultMap"&gt;
      SELECT
          procinst.proc_inst_id_ AS id,                                                  
          amount_VAR.bytes_      AS amount,
          ...
      FROM procinst
          ...
         -- Some JOINS to request vauels
  &lt;/select&gt;
  &lt;/mapper&gt;
  </code></pre>
  
  <p>In runtime I've got an error:</p>
  
  <pre><code>### Error querying database.  Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'amount' from result set.  Cause: org.postgresql.util.PSQLException: Bad value for type float : \xaced00057372000f6a6176612e6c616e672e466c6f6174daedc9a2db3cf0ec02000146000576616c7565787200106a6176612e6c616e672e4e756d62657286ac951d0b94e08b0200007870412547ae
  </code></pre>
  
  <p>I tried to add <code>typeHandeler="org.apache.ibatis.type.FloatTypeHandler"</code>, but it has no influence on error.</p>
  
  <p>I checked out the query at Datagrip and got next result:
  <img src="https://i.stack.imgur.com/QF3Il.png" alt="Screenshot"></p>
  
  <p><strong>So, the question is: how to deserialize value stored in <em>bytea</em> type as object?</strong></p>
  
  <p><strong>Edit:</strong>
  I'm sure that object stored as <em>bytea</em> type, because the value is stored in another table (I use Activi Engine Services to store the values and it's use same Mybatis library).</p>
  
  <p>The table where object is being stored has next structure (take a look at <strong>bytes_</strong> field):</p>
  
  <pre><code>create table act_ge_bytearray
  (
      id_ varchar(64) not null
          constraint act_ge_bytearray_pkey
              primary key,
      rev_ integer,
      name_ varchar(255),
      deployment_id_ varchar(64)
          constraint act_fk_bytearr_depl
              references act_re_deployment,
      bytes_ bytea,
      generated_ boolean
  )
  ; 
  </code></pre>
  
  <p>The object class has next structure:</p>
  
  <pre><code>public class Workflow implements Sortable
  {
      private String id;
      private Float amount;
  
      // getters and setters are ommited
  }
  </code></pre>