-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: problem with sorted set using annotation
PostPosted: Tue Feb 13, 2007 9:40 pm 
Newbie

Joined: Tue May 10, 2005 10:39 am
Posts: 2
Location: Guangzhou China
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.