Ask Your Question
1

What is the method for utilizing the same association multiple times in HQL?

asked 2023-07-18 23:12:08 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-07-18 23:13:01 +0000

plato gravatar image

The method for utilizing the same association multiple times in HQL is by using aliases or joining the association multiple times with different aliases.

Example 1: Using aliases

FROM Employee e JOIN e.department d1 JOIN e.department d2 WHERE d1.name = 'Sales' AND d2.name = 'Marketing'

In this example, we are using aliases d1 and d2 to join the Employee entity with the Department entity twice to get employees who belong to both the Sales and Marketing departments.

Example 2: Joining multiple times

FROM Employee e JOIN e.department d WHERE e.salary > d.maxSalary AND e.salary > d.minSalary

In this example, we are joining the Employee entity with the Department entity twice, using the same association e.department both times, with a different condition each time. This query returns employees whose salary is between the minimum and maximum salary of their department.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-18 23:12:08 +0000

Seen: 10 times

Last updated: Jul 18 '23