Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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!

See Question&Answers more detail:os

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

1 Answer

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...