as title indicates i'm trying select both username , role name using following query.
select u.username, r.name users u, role r inner join users_roles ur on ur.user_id = u.id username = ?;
however i'm getting below error
[2017-04-05 21:34:49] [42p01] error: invalid reference from-clause entry table "u" [2017-04-05 21:34:49] hint: there entry table "u", cannot referenced part of query. [2017-04-05 21:34:49] position: 79
my user entity follows
@entity(name = "users") // postgres doesn't table name "user" public class user { @id @generatedvalue(strategy = generationtype.auto) private long id; private string username; ... @manytomany @jointable( name = "users_roles", joincolumns = @joincolumn( name = "user_id", referencedcolumnname = "id"), inversejoincolumns = @joincolumn( name = "role_id", referencedcolumnname = "id")) private collection<role> roles; ...
and role entity follows
@entity public class role { @id @generatedvalue(strategy = generationtype.auto) private long id; private string name; @manytomany(mappedby = "roles") private collection<user> users; ...
any clues i'm doing wrong?
select users.username, role.name users left outer join users_roles on users.id = users_roles.user_id left outer join role on users_roles.role_id = role.id username = ?
Comments
Post a Comment