This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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 ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

JPA Specifications - dealing with optional parameters

 
Ranch Hand
Posts: 123
1
  • 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!

//edit

I changed to

   

and it works, but the question is, how to make to return all the advertisements if no parameters where passed.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic