• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

HQL Query

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I wonder if anyone can help me. Im brand new to HQL and am struggling a little. Basically I need to write a simple query that selects all values based on a foreign key(pattern_group_id) and store these in a list.

This is what I have so far:

List<String> patternByGroupList = sessionFactory.getCurrentSession()
.createQuery("SELECT * FROM PATTERN p WHERE pattern_group_id = :id")
.setParameter("id", groupName)
.setCacheable(true)
.list();

which is wrong. I need to write it so that it does a sub query within to select the pattern_group_id based on whatever the groupname (which is a String parameter) is. Can anyone point me in the right direction?

Thanks,
 
Greenhorn
Posts: 13
Hibernate Eclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html

Here you have example about writing queries. Take a look. Also did you just copy & paste this code from somewhere and added your select clause?
I'm asking because if you are brand new to Hibernate you shouldn't worry your self with caching! Don't do setCacheable set to true! Your query will work fine without it. When you are familiar with HQL then take time to learn what it means.

A simple query with a WHERE clause looks like this:

Query query = session.createQuery("from Pattern WHERE pattern_group_id > 6);
List id = query.list();

One more thing. I just realized it now looking at your code. If you are getting a FK that is some kind of ID, why are you making a String list? How is that Id defined? Shouldn't it be a integer?

Let me know if anything of these things helped.
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic