java - How to fetch Data using JPA for dynamic Where Clause -
i new jpa. using jpa2.0 in 8.5.5
i have search screen have lot of search criteria's. now, have create query in jpa such way criteria user has selected, automatically check particular column in db.
i not able find solution on that. seems me every search criteria, have write new named query.
any suggestion or pointers appreciated.
you in named query, have check every single possible criteria if null in order avoid null values affect results. beware of unnecessary inner joins, each nullable relation should included left join
select e employee e left join e.department d (:name null or e.name = :name) , (:email null or e.email = :email) , (:deptid null or d.id = :deptid) ...
however, depending on complexity of possible combinations, better option not use named queries, dynamically construct jpql depending on selected criteria.
Comments
Post a Comment