spring Data jpa 一对多关联 动态查询怎么写
请问看得懂java代码吗多表联查动态查询能实现吗。barCode是子表的条件Commodity实体类有个commodityBarcodes;CommodityBarcod...
请问看得懂java代码吗多表联查动态查询 能实现吗。barCode是子表的条件
Commodity实体类有个 commodityBarcodes;
CommodityBarcode里有个barCode条件
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "commodity")
private List<CommodityBarcode> commodityBarcodes;
dao层继承JpaSpecificationExecutor有个findAll(Specification
<e>, Page<e>)方法
Specification接口里怎么动态拼接子表的搜索条件 展开
Commodity实体类有个 commodityBarcodes;
CommodityBarcode里有个barCode条件
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "commodity")
private List<CommodityBarcode> commodityBarcodes;
dao层继承JpaSpecificationExecutor有个findAll(Specification
<e>, Page<e>)方法
Specification接口里怎么动态拼接子表的搜索条件 展开
1个回答
展开全部
predicates.add(cb.like(root.get("commodityBarcodes").get("barCode"), "%" + dto.getBarCode() + "%"));
你试试这样写,我用@OneToOne就是这么写的。感觉这样也差不多
追问
我是@OneToMany
像你这样写会报错
Illegal attempt to dereference path source [null.commodityBarcodes] of basic type; nested exception is java.lang.IllegalStateException: Illegal attempt to dereference path source [null.commodityBarcodes] of basic type
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询