Search code examples
blobmybatisverticavarbinary

retrieve Hex string using MyBatis


I am using Vertica and MyBatis.

  1. I am storing a binary information in Vertica as long varbinary column
  2. I want to retrieve it as an hex, so I have this code in the mapper

<resultMap id="data" type="some_table_name">
        <result property="long_varibary_column" column="long_varibary_column" />
    </resultMap>

<select id=“getlong_varibary_column” resultMap=“data”>

Select to_hex(long_varibary_column)
From some_table_name
Limit 1
</select>

  1. In the model I have used

Public class some_table_name{

 String long_varibary_column;

  Public void setLong_varibary_column(String long_varibary_column){this. long_varibary_column= long_varibary_column;}
}

I have used String in the model, as the query has to_hex(long_varibary_column) even though the column long_varbinary_column is actually a Long varbinary on the table.

When I fetch the data, I get Null.

I even tried with byte[] instead of String long_varibary_column, still, I get Null.

Any clue what is going wrong?


Solution

  • To reference the result by the column name, you need to assign alias to it.
    i.e.

    select to_hex(long_varibary_column) long_varibary_column
    from some_table_name
    limit 1
    

    Here is a demo.