Moja znajomość SQL i JPQL nie są tak wielkie i I zostały próbuje utworzyć kwerendę JPQL z następującą instrukcję SQL:JPQL i Join Table
select group.* from user, user_group, group
where user_group.user_id = user.id
and user_group.group_id = group.id
and user.id = [userID to search]
EDIT: Ups zapomniałem dodać wyszukiwanie identyfikator użytkownika jest częścią zapytania. Chciałbym uzyskać wszystkie grupy, do których należy użytkownik.
Ale po prostu nie mogę uzyskać poprawnej składni. Każda pomoc będzie bardzo ceniona.
Istotne fragmenty kodu:
Group.java
@Table(name = "group")
@Entity
public class Group implements Serializable {
@Id
@GeneratedValue
@Column(name = "id")
private Integer id;
@JoinTable(name = "user_group", joinColumns = {
@JoinColumn(name = "group_id", referencedColumnName = "id")}, inverseJoinColumns = {
@JoinColumn(name = "user_id", referencedColumnName = "id")})
@ManyToMany
private Collection<User> userCollection;
}
User.java
@Table(name = "user")
@Entity
public class User implements Serializable {
@Id
@NotNull
@GeneratedValue
@Column(name = "id")
private Integer id;
@Column(name = "email", unique=true, nullable=false)
private String email;
@ManyToMany(mappedBy = "userCollection")
private Collection<Group> GroupCollection;
}
Co próbujesz zrobić? –