• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to fetch Data using JPA for dynamic Where Clause

 
Alok Agrawal
Greenhorn
Posts: 14
Java jQuery
  • 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.
 
K. Tsang
Bartender
Posts: 3585
16
Android 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic