I have 2 Entities User and AccountBase with a many-to-many relationship.
(我有2个实体,用户和AccountBase具有多对多关系。)
I need to select all AccountBase objects with a selected User ID from the join table. (我需要从联接表中选择具有选定用户ID的所有AccountBase对象。)
I have tried some join queries but don't work. (我尝试了一些联接查询,但是不起作用。)
@Table(name = "ACCOUNT")
@DiscriminatorColumn(name = "ACCOUNT_TYPE", length = 1)
public abstract class AccountBase extends ModelBase {
protected double balance;
protected List<User> users = new ArrayList<>();
@Table(name = "USER_ACCOUNT")
public class User extends ModelBase implements Serializable {
private static final long serialVersionUID = 1L;
protected String name;
protected List<AccountBase> bankAccounts = new ArrayList<>();
// bi-directional many-to-many association to AccountBase
@ManyToMany
@JoinTable(name = "USER_ACCOUNT_ACCOUNT", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = {
@JoinColumn(name = "ACCOUNT_ID") })
public List<AccountBase> getBankAccounts() {
return this.bankAccounts;
}
ask by Phuc Nguyen translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…