PostgreSQL function round and JPA/Hibernate -


i have query executed java application this:

query query = getentitymanager().createquery(hql); 

the query looks this:

string hql = "select * table round(column1, 3) = round(parameter, 3)"; 

here column1 of type double. value holds 143.02856666. need retain value is, business logic need round , compare.

the initial database configured h2 , worked fine. database has been changed postgres , query errors out.

error: function round(double precision, integer) not exist hint: no function matches given name , argument types. might need add explicit type casts.

the round() function in postgres takes numeric datatype , needs cast.

the below query works fine if executed directly in postgres console.

select * table round(cast(column1 numeric), 3) = round(cast(parameter numeric), 3); 

the same java application errors out.

java.lang.illegalargumentexception: org.hibernate.queryexception: not resolve requested type cast : numeric

also tried query query = getentitymanager().createnativequery(hql); results in new error.

org.hibernate.engine.jdbc.spi.sqlexceptionhelper - error: syntax error @ or near "where"

if debug, errors out when below line executed.

list resultlist = query.getresultlist(); 

how rewrite query works against postgres ?

what doing query query = getentitymanager().createquery(hql); calling jpql-query, not support db-functions round(v numeric, s integer).

two suggestions:

  1. use between , maintain jpql-mapping
  2. write nativequery -> query query = em.createnativequery(querystring);

your querystring has altered parameters.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -