Search code examples
hibernatejpahbm2ddl

How do I specify integers to be of a certain length via a JPA annotation


create table foo (id INT(10) not null ...)

Instead of declaring id as "INTEGER", I would like to specify a length restriction as mentioned above.

I use

@Entity class Foo {

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false, insertable = false, updatable = false)
private Integer id;

... }

How should I specify the length restriction in my JPA model class, so that hbm2ddl automatically generates the schema as per my requirement.


Solution

  •  @Id
     @GeneratedValue(strategy = IDENTITY)
     @Column(name = "id",length=50, unique = true, nullable = false, insertable = false, updatable = false)
     private Integer id;
    

    In your case you are use annotaion/JPA. If you used mapping then use like this :

    <property name="id" type="Integer" length="20"/>
    

    try this one