• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin


Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am using user table to fetch the user details
and role table to fetch the roles and description
And we have one more table of user_role_link table in which user_id and role_id is associated in it.
user table doesn't have the role_id and role table doesn't have the user_id,
based on this i want to write a HQL to fetch userlist based of role_id.
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope the following example can help you.

public class Role

private Integer roleId;
private String name;
private Set<User> users;
//setters getters

public class User
private Integer userId;
private String userName;
//setters getters

<class name="User" table="Users">
<id name="userId" column="user_id">
<generator class="native"/>
<property name="userName" column="username"/>


<class name="Role" table="ROLES">
<id column="role_id" name="roleId">
<generator class="native"></generator>
<property name="name" column="role_name"></property>
<set name="users" table="users_roles">
<key column="role_id"></key>
<many-to-many column="user_id" class="User"/>

Query query = session.createQuery("from Role where roleId = ?");
query.setInteger(0, 1);
List<Role> roles = query.list();
for (Role role : roles) {
Set<User> users = role.getUsers();
for (User user2 : users) {
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
    Bookmark Topic Watch Topic
  • New Topic