File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes JPQL - Query Parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPQL - Query Parameter" Watch "JPQL - Query Parameter" New topic

JPQL - Query Parameter

Israel Fonseca

Joined: Aug 29, 2008
Posts: 7
Supose the following situation:

class ObjectA

Integer id;
List<ObjectB> list;

How can i make a JPQL that retrives a list of ObjectA that have at least N ObjectB. N is variable number. Example:

table ObjectA
table ObjectB
[id] [fk_objectA]
1 1
2 1
3 2

My search method would be...

List<ObjectA> search(List<ObjectB> param){
return em.createQuery("from ObjectA o where o have at least these :param").setParameter("param",param).getResultlist()

If param is a list with ObjectB(id=1) it would retrieve: ObjectA(id=1), the same would be true if param was a list with [ObjectB(id=1),ObjectB(id=2)]

Off course that this query don't work, but i want to do something like that. Is it possible? Or do i have to make a lot of string concatenation?


I agree. Here's the link:
subject: JPQL - Query Parameter
It's not a secret anymore!