• 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Hibernate HQL: Query to Criteria

 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I convert this HQL to a criteria query?



There are 3 tables: User, Application, and User2Application.

User2Application is a bridge table and contains an Application object, and User object.

I am trying to retrieve all users who have access to the given application. The HQL query above works fine, however I need to add orderBy and rowCount, and I think using Criteria would be better choice.

Thanks
 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you need to look at one class but return another, I think you'd need to do something like this...



What this does is create a criteria on User2Application saying that the query should find all User2Applications that have the given application. From this set of matches, then return the users found.

For more information you can look at Hibernate tutorial - criteria queries (specifically 15.4) that gives more information on this and how you would expand it to include order by. By that I mean where to put the order by so that the criteria make sense.

Hope that helps,
Rachel
[ September 02, 2008: Message edited by: Rachel Swailes ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, give me the source code of your hibernate entities...
[ September 02, 2008: Message edited by: Alexander Kotlyarov ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!