I hava a user-role many-to-many relationship mapped by annotation using set, and I want the role set to be sorted by role name, here is the code:
User:
private Set<Role> roles = new HashSet<Role>();
@ManyToMany
@JoinTable(name = "USER_ROLE")
@org.hibernate.annotations.OrderBy(clause = "rolename asc")
public Set<Role> getRoles() {
return this.roles;
}
Role:
private Set<User> users = new HashSet<User>();
@ManyToMany(mappedBy = "roles")
public Set<User> getUsers() {
return this.users;
}
and an error occured that the id column can not be found, and I checked the sql generated by hibernate and it turned to be:
select roles0_.users_id as users1_1_, roles0_.roles_id as roles2_1_, role1_.id as id1_0_, role1_.roleName as roleName1_0_, role1_.description as descript3_1_0_ from USER_ROLE roles0_ left outer join t_role role1_ on roles0_.roles_id=role1_.id where roles0_.users_id=? order by roles0_.rolename asc
how can I set the order claus to be role1_.rolename instead of roles0_.rolename?
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html