Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate HQL: Query to Criteria

 
Hanna Habashy
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
 
Rachel Swailes
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 ]
 
Alexander Kotlyarov
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic