如何设置@Column批注使用的precision属性? [英] How to set up precision attribute used by @Column annotation?

查看:531
本文介绍了如何设置@Column批注使用的precision属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常使用java.lang.Integer作为主键.在这里您可以看到一些代码

I often use java.lang.Integer as primary key. Here you can see some piece of code

@Entity
private class Person {

    private Integer id;

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

    }        

}

我需要设置其精度属性值等于8 .但是,当导出架构(Oracle)时,它无法按预期工作.

I need to set up its precision attribute value equal to 8. But, when exporting The 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输出

schema.sql outputs

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

我总是得到10 .有一些解决方法可以使8代替10?

Always i get 10. Is there some workaround to get 8 instead of 10?

推荐答案

Javadoc似乎表明该参数对Integer毫无意义.

Javadoc seems to indicate that parameter isn't meaningful at all for Integer.

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

由于您的列类型不是BigDecimal等,因此休眠状态似乎是正确的忽略方式,而只需创建一个包含32位整数的列即可.

So it would appear hibernate is right to ignore it, as your column type isn't a BigDecimal etc, and just make a column that holds a 32-bit integer.

这篇关于如何设置@Column批注使用的precision属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆