1

I would like to generate a column (abc NUMBER(2)) (at the moment) in oracle:

@Column(length = 2)
private Integer abc;

but still in Oracle, the column created is abc NUMBER(10, 0).

I tried @Digits(integer=2, fraction=0) but I think this would not work as the Java type is Integer.

Java doc for @Digit says:

The annotated element must be a number within accepted range Supported types are:

BigDecimal
BigInteger
String
byte, short, int, long, and their respective wrapper types

null elements are considered valid

but @Digits(integer=2, fraction=0) has no effect on the generated column.

I am looking for a generic solution which could also work on MySQL also.

Mohammad Faisal
  • 5,783
  • 15
  • 70
  • 117
  • The Digit annotation is only for validation of the data and requires validator implementations to throw an exception when the value doesn't match what is defined. It has little to do with JPA and nothing to do with DDL generation in the database. If you are after a specific type in the database, you must define it yourself using the columnDefinition. If it doesn't work on a different database platform, you are stuck - you will have to override it in an orm.xml with specifics for your database. – Chris Sep 06 '17 at 15:47

1 Answers1

3

You could try the precision obtained by java-sql data type mapping

@Column
private Short weightedScore;

Give also a try to BigDecimal specifying precision and scale

@Column(precision = 2, scale = 0)
private BigDecimal weightedScore;

IMHO BigDecimal precision maps quite well with Oracle NUMBER(precision).

Use the precision attribute, i.e.

@Column(precision=2)
private Integer abc;

I'd expect it generates some DDL such as NUMBER(2,0).

See How to specify Double's precision on hibernate?

Davide Cavestro
  • 473
  • 5
  • 13