Hibernate @EntityGraph在实体内获取实体

Hibernate @EntityGraph在实体内获取实体,hibernate,jpa,entitygraph,Hibernate,Jpa,Entitygraph,我正在尝试使用EntityGraph获取所有产品翻译。它工作正常,但也会获取所有延迟获取的实体。 我的产品实体: @Entity @Table(name = "product") @Where(clause = "status = 'ACTIVE'") public class Product implements Serializable { private static final long serialVersionUID = 1L; @Id @Generate

我正在尝试使用EntityGraph获取所有产品翻译。它工作正常,但也会获取所有延迟获取的实体。 我的产品实体:

@Entity
@Table(name = "product")
@Where(clause = "status = 'ACTIVE'")
public class Product implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

...

    @OneToMany(mappedBy = "product")
    private Set<ProductTranslateNew> translates = new HashSet<>();

    //Getters & Setters
我的存储库:

@Repository
public interface ProductRepository extends JpaRepository<Product, Long>, JpaSpecificationExecutor<Product> {

@EntityGraph(attributePaths = {"images", "translates"})
    @Query(value = "SELECT p " +
        "FROM Product p left join p.translates t " +
        "WHERE p.supplier.id = :suppId AND t.language = :lang",
        countQuery = "SELECT count(p) " +
            "FROM Product p left join p.translates t " +
            "WHERE p.supplier.id = :suppId AND t.language = :lang")
    Page<Product> getAllProductBySupplierId(@Param("suppId") Long id,
                                               @Param("lang") String language,
                                               Pageable pageable);
}
@存储库
公共接口ProductRepository扩展了JpaRepository,JpaSpecificationExecutor{
@EntityGraph(AttributePath={“图像”,“翻译”})
@查询(value=“选择p”+
“从产品p左连接p.t”+
“其中p.supplier.id=:suppId和t.language=:lang”,
countQuery=“选择计数(p)”+
“从产品p左连接p.t”+
“其中p.supplier.id=:suppId和t.language=:lang”)
Page getAllProductBySupplierId(@Param(“SupplierId”)长id,
@Param(“lang”)字符串语言,
可寻呼(可寻呼);
}

当我调用getAllProductBySupplierId方法时,我在Translate中获取产品。它还获取产品。
有没有办法不获取实体-用FetchType.Lazy注释?

因为它已经获取作为起点(“两个”产品是相同的)。将一个完全不同的实体关系添加到ProductTranslateNew中并选中它…它不会被提取。因为它已经被提取为起点(“两个”产品是相同的)。将一个完全不同的实体关系添加到ProductTranslateNew中并选中它…它不会被提取。
@Repository
public interface ProductRepository extends JpaRepository<Product, Long>, JpaSpecificationExecutor<Product> {

@EntityGraph(attributePaths = {"images", "translates"})
    @Query(value = "SELECT p " +
        "FROM Product p left join p.translates t " +
        "WHERE p.supplier.id = :suppId AND t.language = :lang",
        countQuery = "SELECT count(p) " +
            "FROM Product p left join p.translates t " +
            "WHERE p.supplier.id = :suppId AND t.language = :lang")
    Page<Product> getAllProductBySupplierId(@Param("suppId") Long id,
                                               @Param("lang") String language,
                                               Pageable pageable);
}