Vala
Vala

Reputation: 5674

How can I round a column value with a JPA query?

I need to compare for equality on a number stored in the database as a floating point number (this has to support multiple databases and I haven't got any control over how it's stored), but of course equality will only get you so far with an approximated value, so I need to round the column value like this:

select * from x where round(col, 2) = ?;

Unfortunately I can't seem to find a way of doing that in JPQL. Is there any way to achieve this (without changing the database)?

Upvotes: 0

Views: 4045

Answers (1)

Christian Kuetbach
Christian Kuetbach

Reputation: 16060

I have two ideas to solve this problem:

  1. make a between query

  2. use a native query

Upvotes: 4

Related Questions