how to set parameter into native query between single quotation in java hibernate?

s.morteza malekabadi :

Below is the simple example which explain my problem

Query(name = "select p.* , pr.actual_date_time , count(*) " +
"from player p  " +
"inner join app.player_reports pr ON pr.player_id = p.id " +
"where pr.actual_date_time between  now() - interval '?1 day' 
   and now() - interval '0 day' " ,nativeQuery = true)
List<PlayerEntity> findCheaters(@param("NumberDays") int number )

this is my query, I want to put "NumberDays" between single quotation and substitute with "?1".

I would be glad to help me, and thank you

a_horse_with_no_name :

You can't parametrize the value for the interval constant, but you can simply multiply the base unit with a parameter:

pr.actual_date_time between  now() - (interval '1 day' * ?) and now()

Then pass the number of days you want as an integer to the PreparedStatement.


Note that the - interval '0 day' is useless

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=81486&siteId=1