Laures
Laures

Reputation: 5489

Unsigned Int in JPA and Hibernate

What can i do so JPA (i use Hibernate) creates Columns with Unsigned types? Currently all my ID columns are signed.

Upvotes: 11

Views: 16460

Answers (3)

vvs14
vvs14

Reputation: 790

MySQL has excellent documentation addressing the same problem. Link

If you are creating tables using DDLs (manually or using DB migration tools) and only want to understand which Java data type best suits your MySQL Unsigned Int column, the answer is long/Long.

Upvotes: 0

chimpui
chimpui

Reputation: 1

In MySQL Workbench "UNSIGNED" should come after "INT(11)"

Upvotes: 0

Matt Ball
Matt Ball

Reputation: 359816

Using the columnDefinition property on the @Column annotation should do it. Taking a total guess at the SQL type you're going for:

private long foo;

@Column(columnDefinition = "UNSIGNED INT(11)")
public long getFoo()
{
    return foo;
}

N.B. Not all databases (like SQL Server, I think) support unsigned int types.

Upvotes: 20

Related Questions