We develop a Java EE application that uses a Postgres database as persistence medium. Some of our entity attributes are mapped as float. Sorting this columns leads to the following result:

  SCORE
  1.0
  100.2
  2.0
  20.0
  3.0

The result I've expected is:

  SCORE
  1.0
  2.0
  3.0
  20.0
  100.2

The float attrributes are mapped with datatype float(8) in postgres database. With the following plain sql query sorting works as expected:

SELECT score FROM Evaluation ORDER BY score::float

Also changing the column type to "real" works. Is there any way (except using column definition) to get this work with jpa?

有帮助吗?

解决方案

Sorry for your effort :(. I had have a look again on the domain model. They saved the score within two columns. One column is float, the other is an varchar. Sorting action sorts the varchar column, so alphanumeric sorting is ok.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top