1

i have two entities : Customer and User. They have a many to many relationship. Assume I have the following data in database.

Customer
-------------
id  | name 
1   | customer

User
-------------
id  | name 
1   | user1 
2   | user2 

Customer_use
-------------
customer_id  | user_id
1            | 1
1            | 2

My question is how to return a query result like below:

customer | users 
customer | user1,user2
Steven Ryssaert
  • 1,989
  • 15
  • 25
user744574
  • 41
  • 2
  • 4
  • HQL depends on the classes, not the tables. So the structur of the tables are not that important then the structure of the entities. If you don't know how to map it, ask another question. – Stefan Steinegger May 11 '11 at 08:52

2 Answers2

1

Using the joins you can fetch the records by single HQL query for more reference click here

Rupeshit
  • 1,476
  • 1
  • 14
  • 23
1

HQL is object oriented, which means that you return objects. If you want to return all customers, just do select c from Customer c and all its relationships comes with the object.

ssedano
  • 8,322
  • 9
  • 60
  • 98