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

Where to run complex algorithms? Server side or Client side? [closed]
How to hide the public API of dependencies (.jar libraries) in Android module?
Simple PowerMock test gives an error, android studio project
How to differentiate which connection pool getting error on multiple connection pool?
Implement recursive MergerSort in Java
Self executing command
Timeout concept in JAVAFX8 [duplicate]
Base condition in recursive methods
How to Include dependencies to pom.xml for uploading to bintray jcenter
do all the subclass's constructors with parameters needs super(args) when superclass only have one constructor with parameters?
calling generic methods without cast
Closing a JFrame via JButton while opening a new JFrame [duplicate]
How to do Kendo UI MVVM UI automation test?
Showing parameter number 2 is not an OUT parameter while calling a procedure using java
Connect 4 against the computer [closed]
MappingJacksonHttpMessageConverter adds enclosing [ ]

Categories

HOME
xamarin
hive
pypi
openstack
iterator
include
spring-cloud-stream
rdf
c#-2.0
yum
echarts
fancybox
elasticsearch-hadoop
tomcat6
offline
resize
messages
fallback
zebra-printers
systemc
saxon
reactcsstransitiongroup
accessor
google-search-api
zurb-foundation-6
jndi
crosstab
java-7
angular2-aot
microsoft-sync-framework
django-storage
atlassian-crucible
gsoap
madlib
contact-form
webtest
geopositioning
overriding
swisscomdev
automake
libvpx
twitch
splice
cookiecutter-django
squib
hp-ux
fakeiteasy
no-www
s
thin
convertapi
executenonquery
angular-resource
domain-model
fancybox-2
knockout-components
nodebb
google-perftools
np-complete
pdfclown
synchronous
pintos
parallel-data-warehouse
google-feed-api
dstu2-fhir
qcustomplot
pyke
browser-link
msys
t4mvc
python-3.2
fouc
kcachegrind
service-accounts
splash
proj4js
notify
python-green
code-access-security
tld
meteor-velocity
imdbpy
padarn
factory-method
jquery-knob
cisco-jtapi
regsvr32
enter
mercurial-server
genshi
django-tagging
winbugs14
gallio
routedevent
database-management
nintendo-ds
brewmp
audio-capture

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App