Dota2
Dota2

Reputation: 474

How to run native postgres query using spring-data-jpa

I am using spring-data-jpa to run native postgres queries. The query is performed on entity's jsonb data. I can run the raw query on db server with success:

SELECT e.* 
FROM public.entity e where e.json ? 'salary' and e.json ->> 'salary' > '10000';

But, since spring-data-jpa also supports ? for the parameterized queries, there seems to be conflict in the grammer of the query, therefore application eventually fails to even start.

@Query(value = "select e.* from Entity e where e.json ? 'salary' and e.json->> 'salary' > ?1", nativeQuery = true)
List<Lead> getEntitiesBySalaryGreaterThan(String value);

}

Please let me know the workaround or correct way of executing the intended native query in spring-data-jpa env

Upvotes: 1

Views: 479

Answers (1)

ValerioMC
ValerioMC

Reputation: 3186

Is it possible that you need to escape ? as described here?

Upvotes: 1

Related Questions