java


Using JPA native query with zero or more parameters


Goal: I am trying to build query via JPA which returns a list of locations, nearest to the coordinates passed to the query. The ability to apply filter(s), sort and paginate on the query are required. The following native sql query is what I came come up with so far:
select s.*,sqrt(power(abs(:latitude-g.latitude),2)+power(abs(:longitude-g.longitude),2)) as d from geolocations g inner join salons s on g.zip=s.zip where LOWER(s.salon_name) like LOWER(CONCAT('%',:q,'%')) order by d asc limit :pageSize offset :offset
Paganation, some sorting, and location based search are all working, but I cannot get filtering to work.
The filter requirement states that a user must also be able to filter search results(0 or more filters) by fields, like owner,state,zip... I want to use something like querydsl or the JPA Specification object to build a small query language but I cannot build out a working implementation given the fact that I am using a native query. I am looking for any recommendations on how I could implement the field filters into my existing repository.
Here is my entire repository:
public interface SalonRepository extends JpaRepository<Salon,String>, JpaSpecificationExecutor<Salon>{
#Query("select s from Salon s where s.city = :city and s.state = :state")
Page<Salon> findByCity(#Param("state")String state,#Param("city")String city,Pageable pageable);
#Query("select s from Salon s where s.salonName = :name")
Page<Salon> findByName(#Param("name")String name,Pageable pageable);
//THIS IS THE ONE I WANT TO ADD THE USER DEFINED FILTERS TO
#Query(value = "select s.*,sqrt(power(abs(:latitude-g.latitude),2)+power(abs(:longitude-g.longitude),2)) as d from geolocations g inner join salons s on g.zip=s.zip where LOWER(s.salon_name) like LOWER(CONCAT('%',:q,'%')) order by d asc limit :pageSize offset :offset", nativeQuery = true)
List<Salon> findNearest(#Param("latitude")float latitude,#Param("longitude")float longitude,#Param("q")String query,#Param("pageSize")int pageSize,#Param("offset") int offset);
#Query(value = "select sqrt(power(abs(:latitude-g.latitude),2)+power(abs(:longitude-g.longitude),2)) as d from geolocations g inner join salons s on g.zip=s.zip where LOWER(s.salon_name) like LOWER(CONCAT('%',:q,'%')) order by d asc", nativeQuery = true)
List<Float> findNearestInt(#Param("latitude")float latitude,#Param("longitude")float longitude,#Param("q")String query);
#Query("select s from Salon s where lower(s.salonName) like LOWER(CONCAT('%',:salonName,'%'))")
Page<Salon> findAll(#Param("salonName")String salonName,Pageable pageable);
}
After hours of searching, I am fairly certain I am on the wrong track given the lack of information I've uncovered.
Any and all help is appreciated!

Related Links

sharing images to whatsapp directly without asking for options in adroid [duplicate]
Java - Lists and methods
Run-time error. Integer convert to string
How to pass a parameter to a callback method
Why is not detecting my parametrized class type?
How can I get a List of objects using Unirest for Java?
Error inflating class AppCompatButton
How to extract a string from a bean returning string array in XML
Scanner continuous loop
Findbugs is telling me that I have comparison of nonnegative value with -1 for no apparent reason
passing value from signup to register if validation is true
Cant extract single files from Tar, 0kb size, Java
check for numeric input java
cannot find symbol, keyEvent constants java
Comparing two numbers using if/else statements
Certificate Authentication and Authorization with Apache from a Java Application

Categories

HOME
wso2-am
date
mockito
onedrive
webstorm
alfresco
tizen-web-app
cross-validation
kentor-authservices
wheelnav.js
vb.net-2010
size
fallback
try-catch
serverless-framework
ghc
reactcsstransitiongroup
extjs5
realex-payments-api
lcd
xpages-ssjs
traffic
rst2pdf
maquette
elasticsearch-net
r-raster
react-chartjs
bcd
javascriptcore
framemaker
repo
y86
amazon-kinesis-kpl
hexo
automake
streamsets
optix
http-live-streaming
android-mediaprojection
auto-update
outlook-2013
smartcontracts
qsslsocket
prolog-setof
idisposable
setter
lift-json
typed-lambda-calculus
lync-client-sdk
django-scheduler
redundancy
minimization
eventkit
root-framework
medium.com
heidisql
skobbler-maps
oauth2client
revolution-r
qtableview
metaclass
python-3.2
simple-framework
deis
apache-commons-fileupload
sortedlist
proj4js
truevault
javax.mail
tt-news
gui-test-framework
java-metro-framework
googlemock
sgen
fluentautomation
rtmfp
typo3-neos
ivyde
.aspxauth
dir
inbox
eclipse-memory-analyzer
back-stack
word-processor
pysimplesoap
cascalog
osql
boost-filesystem
mercurial-server
horizontal-accordion
xtype
self-extracting
mysql-error-1005
cxxtest
getresponsestream
forums
firefox-5
photoshop-cs4
wsdl.exe
misv

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App