• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Write Sub Query in Hibernate help

 
jone wiilum
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All.
Please help me to right sub query in Hibernate
i have 2 table
1.quotes
2.programs

my requirement is that when i apply filter apply on quotes table
e.g

select quote_id,Quote_name,Quote_dir from quote q where q.quote_name like 'j%';

i get all quote_id from above query

i need to pass above quote_id to another table (programs)
i need following query in Criteria format

select q.quote_id,q.Quote_name,q.Quote_dir ,p.program_name from quote q,program p where q.quote_name like 'j%'
and p.quote_id in(select quote_id from quote where quote_name like 'j%');

please help me its very very urgent
i hope you all geeks help me


Thanks





 
Brett Maclean
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jone,

I'm not sure what your underlying schema is but can you not write the query using a join rather than a subquery:



Again, depending on your Hibernate mappings this relationship (between Quotes and Programs) may already be defined so you might be able to return the associated programs as a collection in your quote after filtering on the quote name. This of course will depend on your mappings, whether the association is set up, and which direction the association runs in.

HTH



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic