0
タイトルは、次のクエリを使用してユーザー名と役割名の両方を選択しようとしていることを示しています。私はユーザー名と役割名を選択してください
[2017-04-05 21:34:49] [42P01] ERROR: invalid reference to FROM-clause entry for table "u"
[2017-04-05 21:34:49] Hint: There is an entry for table "u", but it cannot be referenced from this part of the query.
[2017-04-05 21:34:49] Position: 79
以下のエラーを取得していますが
@Entity(name = "users") // Postgres doesn't like the 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;
...
をたどり、
@Entity
public class Role {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String name;
@ManyToMany(mappedBy = "roles")
private Collection<User> users;
...
どれを次のように私の役割実体があるとして私のユーザエンティティがある
select u.username, r.name
from users u, role r
inner join users_roles ur
on ur.user_id = u.id
where username = ?;
私が何をやっているのかについての手がかりng?
この回答に文脈を追加してください。このクエリは何をしますか?これは元の質問をどうやって解決しますか? –
クエリは、最初の列がユーザー名で、2番目がロールの名前であるタプルのリストを返します。私は春のセキュリティと組み合わせてこれを使用しています。 – user672009