I have 2 classes in a one-to-many relationship and a HQL query that is a bit strange. Even if I have read some questions already posted, it does not seem clear to me.
Class Department{
@OneToMany(fetch=FetchType.EAGER, mappedBy="department")
Set<Employee> employees;
}
Class Employee{
@ManyToOne
@JoinColumn(name="id_department")
Department department;
}
When I use the following query I get duplicates Department objects:
session.createQuery("select dep from Department as dep left join dep.employees");
Thus, I have to use distinct:
session.createQuery("select distinct dep from Department as dep left join dep.employees");
Is this behaviour an expected one? I consider this unusual, as comparing it with SQL.
This question is thoroughly explained on Hibernate FAQ: