我有 2 个具有多对多关联的实体类。
调制点:
@Entity
@Table(name = "MOD_PM")
public class ModPm extends WebPageObject implements Serializable, IDBNamedEntity {
private static final long serialVersionUID = 1L;
public final static String Q_GET_WITHOUT_STATUS_FOR_SCOPE = "ModPm.getWithoutStatusForScope";
@Id
private long id;
....
@ManyToMany
@JoinTable(name = "MOD_PM_SCOPE_TYPES",
joinColumns = @JoinColumn(name = "PM_ID"),
inverseJoinColumns = @JoinColumn(name = "SCOPE_TYPE_ID")
)
private List<ModScopeType> modScopeTypes;
模组范围类型:
@Entity
@Table(name = "MOD_SCOPES")
@Cacheable
public class ModScopeType extends WebPageObject implements Serializable {
private static final long serialVersionUID = 1L;
public final static String Q_GET_ALL = "ModScopeType.getAll";
@Id
@Column(name = "ID")
private long id;
....
//bi-directional many-to-many association to ModPm
@ManyToMany
@JoinTable(name = "MOD_PM_SCOPE_TYPES",
joinColumns = @JoinColumn(name = "SCOPE_TYPE_ID"),
inverseJoinColumns = @JoinColumn(name = "PM_ID")
)
private List<ModPm> modPms;
是否可以从 MOD_PM 表中选择在 MOD_PM_SCOPE_TYPES 表中有 SCOPE_TYPE_ID=1 记录的实体?
本机 SQL 查询:
SELECT ID, NAME FROM MOD_PM WHERE ID IN (SELECT PM_ID FROM MOD_PM_SCOPE_TYPES WHERE SCOPE_TYPE_ID=1)
如何将此查询转换为 JPQL?