1

What is the recommended way to keep / map Java Hibernate entity -> PostgreSQL for the type BigDecimal? Right now I keep them as simple VARCHAR (character varying) and I have no problems with "float values inequality" (where any random number appears on the high position) but when the data is being displayed (hundreds of thousand rows) in tables (in my solution) I need to convert String to BigDecimal as data can be sorted. I consider to swap VARCHAR to NUMERIC(19,4).

  • Would be nice if I would force BigDecimals from my entity to keep ALWAYS scale == *4.
  • Does the problem with "float - values inequality" occures when NUMBER(19, 4) will be used?
Bartek Szczypien
  • 333
  • 4
  • 17
  • I know that Number should be fixed (in real from what I know, it depends on database), but what if I set new BigDecimal(1) or new BigDecimal(1.2)? Is there a case that something else than 0 appers on decimal places in PostgreSQL? I work with money so I cant afford to make a mistake – Bartek Szczypien Jan 14 '17 at 15:53
  • I dont use it, it is only example. The only types I use are BigDecimal and String (from input) – Bartek Szczypien Jan 14 '17 at 16:33
  • I, personally, live well with numeric storage in `@Column(name = "sum_operation", scale = 2, precision = 20) @NotNull private BigDecimal sumOperation;` and this works for me well, also with numerics I am able to use pure sql agregation, etc. – Ilya Dyoshin Jan 14 '17 at 18:43

0 Answers0