我有 3 个 JPA 实体,例如:
@Entity
public class Link implements {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "network", referencedColumnName = "id")
private Network network;
//...
}
@Entity
public class Network implements LinkOwner {
@OneToMany(mappedBy = "network")
@Cascade(value = { CascadeType.ALL })
private Set<Link> links;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "project", referencedColumnName = "id", nullable = false)
private Project Network.project;
//...
}
@Entity
public class Project {
@OneToMany(mappedBy = "project", orphanRemoval = true)
@Cascade(value = { CascadeType.ALL })
@Fetch(FetchMode.SELECT)
private Set<Network> networks;
}
我做了一个 JPA 查询,例如:
SELECT l FROM Link l left join fetch l.subnetwork sann
where sann.project.id = :projectId
它会生成类似于以下内容的 SQL 查询:
select * from RMT6.link, SUBNETWORK where link.subnetwork = SUBNETWORK.id
and SUBNETWORK.project=?
如何触发仅选择第一个实体的字段并排除第二个实体的字段的 JPQL 查询?我需要在我的 JPQL 查询中进行哪些更改?