0

I'm trying to map a tinyint(1) column in Hibernate. For requirements, I need to save value "2" in the column but I can't change the sql type of it. If I declare it as an Integer in my class the hibernate validation fail. How can I get validation working and having the column int or byte to save value 2 in it?

this is my code:

<property name="flag" type="java.lang.Integer"> 
<column name="flag" not-null="true" sql-type="TINYINT"/> 
</property>

I need to save value 2 into flag column

vjok
  • 33
  • 1
  • 9

2 Answers2

0

Try sql-type="BIT" instead of sql-type="TINYINT"

Gleb Kogtev
  • 111
  • 1
  • 3
  • 10
  • I tried this: but validation is still failing with: Found: bit, expected: integer – vjok Mar 21 '16 at 10:54
  • Wow, I deleted this comment, because I thought it's stupid. I'm glad, that it helped. Could you please accept my answer? Thanks. – Gleb Kogtev Mar 21 '16 at 15:40
0

Just execute below statement-

alter table my_table modify column my_col tinyint;

Actually some framework treat tinyint(1) as boolean type means accept only 0 and 1 even tinyint can handle upto 127 as signed and upto 255 as unsigned values.

As per mysql, tinyint(1) is same like tinyint or tinyint(4) but this is framework property which treat tinyint(1) as boolean but tinyint(2) or just tinyint as normal integer.

Zafar Malik
  • 6,734
  • 2
  • 19
  • 30