0

我有 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 查询中进行哪些更改?

4

1 回答 1

1

我认为,根据您的实体关系,您不需要使用JOIN查询。

SELECT * FROM LINK l WHERE l.network.project.id = :projectId
于 2013-07-17T11:58:05.223 回答