• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

JPA Specifications - dealing with optional parameters

Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to create dynamic query using JPA specification, but I'm not sure whether I understood the JPA specification properly. I was using https://www.baeldung.com/spring-data-criteria-queries to write the code. The case is, I got some paramters that are optionals, so first I've written all etc alone. like this (from above site):

while scrolling down the site I could read about JPA specifiaction and it looked much more better, because within each parameters I got next if using above solution.

Using JPA specification the code looks like this for now:

As you can see code looks much more better, I got rid of boiler plate, but the problem is, just those advertisements are returned that meet all requirements so it has category/city/proper title.

If I got

and if I put only Warsaw I want it to be returned, if I put only random (as title) I want it to be returned etc etc, for now if I put Warsaw, random (as title), MUSIC Could you tell me how to do it?

PS: The code  I write is kotlin, but it is very similiar to java so you can propose solution in java if you want.
Thanks a lot for help!


I changed to


and it works, but the question is, how to make to return all the advertisements if no parameters where passed.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic