假设我有 2 个通过一对多关系连接的表
public class Slave
{
@Id
@Column(name = "id")
long id;
@JoinColumn(name = "master", referencedColumnName = "id")
Master master;
}
public class Master
{
@Id
@Column(name = "id")
long id;
@OneToMany(mappedBy = "master", targetEntity = Slave.class)
Collection<Slave> slaves;
}
是否可以创建 CriteriaQuery 以选择具有已知 id 的 Master 的所有 Slaves?要生成这样的 SQL:
SELECT * FROM slave s WHERE s.master=XXX;
它不应该CriteriaQuery
只是像这样的“本机查询”
_entityManager.createNativeQuery( "SELECT s FROM master s WHERE s.master = ?1" );
query.setParameter( 1, XXX );
先感谢您