Spring 如何在一对多的情况下加入JPA?

Spring 如何在一对多的情况下加入JPA?,spring,jpa,spring-data-jpa,jpql,Spring,Jpa,Spring Data Jpa,Jpql,我有两个实体和产品具有一对多关系,如下所示- @Entity public class Outlet{ @Id @GeneratedValue(strategy=GenerationType.IDENTITY) Long id; @Fetch (FetchMode.SELECT) @OneToMany(mappedBy = "outletProduct",fetch = FetchType.LAZY) List<Product> products; 现在我想要的是那些产品是真实

我有两个实体和产品具有一对多关系,如下所示-

@Entity
public class Outlet{

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

@Fetch (FetchMode.SELECT)
@OneToMany(mappedBy = "outletProduct",fetch = FetchType.LAZY)
List<Product> products;
现在我想要的是那些产品是真实的

我正在为JPQL写作-

 @Query("Select op From Outlet op  join op.products pro where pro.isActive=1  order by op.id")
 List<Outlet>  findAllByVarietiesPriceTimePeriodIn( );
我想要至少有一个产品的出口,但我不想要虚假的产品。现在我得到了清单上的所有产品

它是,但将使用
连接获取

Select op From Outlet op join fetch op.products pro where pro.isActive = 1 order by op.id

想发布真正的JPQL吗?因为您发布的内容无效
WHERE和pro.isActive=1
。完成此操作后,发布所选JPA提供商在数据库中执行的SQL(在JPA提供商日志中)@BillyFrost更新了JPQL,请检查。查询将返回至少有一个活动值为1的产品的所有出口。这就是你要问的for@BillyFrost不,这不是我想要的,请检查更新后的问题以获得结果。我只想要那些具有与之对应的活动产品的门店。正如我已经说过的,如果您不了解结果,请查看为任何JPQL查询执行的生成SQL。您建议的SQL仍然可以返回
Outlet
,其中有一个
产品处于非活动状态(如果它也有一个处于活动状态)。
SELECT * FROM outlet join product on product.outlet_id= outlet.id where product.is_active=1 ;
Select op From Outlet op join fetch op.products pro where pro.isActive = 1 order by op.id