0

I have a user table with different types of users. The type of the user is determined by user_type column in user table. I have a company table which has one to many relationship with User. I have different classes for different users like Guest, Admin (children of User class) each with a discriminator value.

My Company class has:

private Set<Guest> guests;

private Set<Admin> admins;

How can I write a single hql query to join company and user table to populate guest users into guest set and admin users into admin set?

Like select company left outer join fetch company.guests left outer join admin.guests. I cannot find a way to include user_type while making these joins.

Adithya Puram
  • 303
  • 2
  • 6
  • 23
  • Your mapping of the entities is where you set the information about how to join the tables. In your query you only need to refer to your business entities. – carbontax Sep 15 '14 at 12:26
  • I agree, but how can you create mapping across multiple columns? Especially when you are trying to do a join based on a constant value. Like company left outer join user on user.company_id = company.company_id and user.user_type = 'Guest' – Adithya Puram Sep 15 '14 at 20:53
  • Please update your question and include the mapping of your classes. – carbontax Sep 16 '14 at 11:12

0 Answers0