0

I created a JPA Entity with below precision and scale for MySQL DB. But it creates precision and scale wrongly.

Is fixing the table manually the only option? Or can it be fixed in the code?

I use Springboot 1.5.7

JPA Entity:-

@Column(name = "neat_material_cost", columnDefinition = "decimal", precision = 30, scale = 20)
private BigDecimal neatMaterialCost;

@Column(name = "percent_weighed_input_value", columnDefinition = "float", precision = 5, scale = 2)
private Float percentWeighedInputValue;

@Column(name = "percent_dilution_input_value", columnDefinition = "float", precision = 5, scale = 2)
private Float percentDilutionInputValue;

But it created columns with wrong column size and decimal digits as below,

es

Jay
  • 9,189
  • 12
  • 56
  • 96

1 Answers1

2

columnDefinition and precision/scale are mutually exclusive. If you provide a columnDefinition, then that exact string is used verbatim for the column type definition, ignoring any values provided for length, precision, and scale.

What you want is columnDefinition = "decimal(30, 20)" and columnDefinition = "float(5, 5)" respectively.

crizzis
  • 9,978
  • 2
  • 28
  • 47