How to set accuracy attribute used by @Column annotation?

I often use java.lang.Integer as the primary key. Here you can see the code snippet

@Entity
private class Person {

    private Integer id;

    @Id
    @Column(precision=8, nullable=false) 
    public Integer getId() {

    }        

}

I need to set its precision attribute value to 8 . But when exporting a schema (Oracle), it does not work as expected.

AnnotationConfiguration configuration = new AnnotationConfiguration();
configuration
    .addAnnotatedClass(Person.class)
    .setProperty(Environment.DIALECT, "org.hibernate.dialect.OracleDialect")
    .setProperty(Environment.DRIVER, "oracle.jdbc.driver.OracleDriver");

SchemaExport schema = new SchemaExport(configuration);
schema.setOutputFile("schema.sql");

schema.create(true, false);

schema.sql output

create table Person (id number(10,0) not null)

I always get 10 . Is there a workaround to get 8 instead of 10?

+2
source share
2 answers

Javadoc seems to indicate that for Integer, the parameter does not make sense at all.

http://java.sun.com/javaee/5/docs/api/javax/persistence/Column.html#precision%28%29

, , hibernate , , BigDecimal .., 32- .

+2

columnDefinition.

Javadocs:

ColumnDefinition           () SQL, DDL .

@Entity
private class Person {

    private Integer id;

    @Id
    @Column( columnDefinition="number(8,0)", nullable=false) 
    public Integer getId() {

    }        

}
+2

Source: https://habr.com/ru/post/1766236/


All Articles