Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

java - How to specify Double's precision on hibernate?

I try to create a table from hibernate annotations. I need to have a column of Double type, with the length specified like : (10,2). So SQL syntax show like:

... DOUBLE(10,2) ....

I have tried to do that:

@Column(length = 10, precision = 2) ...

but when i look at my created table, it is not specified the length for Double column. Does hibernate has solution for that or is it necessary to alter table configuration by hand?

Thanks!

question from:https://stackoverflow.com/questions/4078559/how-to-specify-doubles-precision-on-hibernate

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The length element of the Column annotation applies only if a string-valued column is used. In your case, you should use the precision and the scale elements.

@Column(precision=10, scale=2)

Here is what the specification writes about them:

  • int - precision - (Optional) The precision for a decimal (exact numeric) column. (Applies only if a decimal column is used.)
  • int - scale - (Optional) The scale for a decimal (exact numeric) column. (Applies only if a decimal column is used.)

References

  • JPA 1.0 Specification
    • Section 9.1.5 "Column Annotation"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...