Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate - How to provide right mapping to integer type?

I'm executing my maven build and it throws this exception:

Last cause: Wrong column type in x.clients for column type. Found: tinyint, expected: integer

I'm mapping like this:

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

And I'm creating the column using InnoDB like this: id int NOT NULL UNIQUE AUTO_INCREMENT

Shouldn't this be ok? Why is it saying that he is finding tinyint?

like image 902
Comic Sans MS Lover Avatar asked Jan 15 '23 17:01

Comic Sans MS Lover


1 Answers

I know this question is (really!) old, but:

TINYINT represents 8-bit values. It's mapped to byte/Byte. It has a minimum value of -128 and a maximum value of 127 (inclusive) in both cases.

SMALLINT represents 16-bit values. It's mapped to short/Short.

INTEGER represents 32-bit values. It's mapped to int/Integer.

BIGINT represents 64-bit values. It's mapped to long/Long.

So, you can't map a tinyint using an Integer; you must use a Byte.

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html http://dev.mysql.com/doc/refman/5.7/en/integer-types.html

like image 106
Pedro Náñez Avatar answered Jan 18 '23 07:01

Pedro Náñez