Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

JPQL - Query Parameter

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
[id]
1
2
------------------
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?

Thanks!

Israel
 
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic