使用 Hibernate 映射 ORACLE 的 NUMBER 类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/343902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 17:32:22  来源:igfitidea点击:

Mapping ORACLE's NUMBER Type with Hibernate

oraclehibernatemapping

提问by

I have a table in a ORACLE 10g database with a column "kzCode NUMBER(1)".

我在 ORACLE 10g 数据库中有一个表,其中有一列“ kzCode NUMBER(1)”。

If I try to map this with Hibernate annotations in JBOSS Server WebApp like this:

如果我尝试在 JBOSS Server WebApp 中使用 Hibernate 注释来映射它,如下所示:

@Column(nullable=false)
private Integer kzCode;

I got an error:

我有一个错误:

org.hibernate.HibernateException: Wrong column type: kzCode, expected: integer

I also tried

我也试过

@Column(nullable=false) private BigInteger kzCode;

error:

错误:

org.hibernate.HibernateException: Wrong column type: kzCode, expected:numeric(19,2)

I don't really know, what Java type to take.

我真的不知道要采用哪种 Java 类型。

回答by

ok, got it!

好的,我知道了!

I had a wrong dialect property in persistence.xml file. Now all works fine..

我在persistence.xml 文件中有一个错误的方言属性。现在一切正常..

回答by Paul Croarkin

@Column(nullable=false)
private Boolean kzCode;

or if you really want it to be a number, change the Oracle type to NUMBER(36, 0) and use long or Long in your Java.

或者,如果您真的希望它是一个数字,请将 Oracle 类型更改为 NUMBER(36, 0) 并在您的 Java 中使用 long 或 Long。