Win a copy of Svelte and Sapper in Action this week in the JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to fetch Data using JPA for dynamic Where Clause

 
Greenhorn
Posts: 14
jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to JPA. I am currently using JPA2.0 in WAS 8.5.5

I have a search screen where we have lot of search criteria's. Now, I have to create Query in JPA such a way that any criteria user has selected, it automatically check for that particular column in DB.

I am not able to find any solution on that. It seems to me that for every search criteria, I have to write new named Query.

Any suggestion or pointers will be appreciated.
 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Alok Agrawal wrote:I am not able to find any solution on that. It seems to me that for every search criteria, I have to write new named Query.

Any suggestion or pointers will be appreciated.



A named query for every search criteria is overkill.

Basically you are trying to append the column name to the existing where in the plain sql.

You may want to look into dynamic queries using EntityManager. Have a look here to check out how dynamic queries compare to named queries.
 
We begin by testing your absorbancy by exposing you to this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic