I know there are many topics around this, but I can't find a solution to my problem. I know if I use "distinct" and "order by" with hibernate, the column from the order by has to be in the select clause. The other articles just say that the column must be in select, but I haven't found an example how this is possible to achieve.
This is my Class:
@Entity
@Table(name = "DANCE")
public class Dance implements Serializable {
@Id
private int tanzid;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SID")
private School school;
@Basic
@Column(name = "titel")
private String titel;
(getter setter...)
My (not working) query:
SELECT distinct d FROM Dance d order by d.school.schoolname
If I do order by title for example it is working. I have tried to set the schoolname in the select clause:
SELECT distinct d, d.school.schoolname FROM Dance d order by d.school.schoolname
but then hibernate is complaining that the return type of the query isn't from type "Dance.class"
How can I achieve an order by schoolname.
Thank you