문제

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