Java Spring jpa规范或子句返回空列表

Java Spring jpa规范或子句返回空列表,java,spring,spring-boot,spring-data-jpa,specifications,Java,Spring,Spring Boot,Spring Data Jpa,Specifications,我正试图在我的项目中实现这一点: Specification<Delivery> shipmentSpec = ((root, query, builder) -> builder.or(builder.equal(root.join("entries").get("shipment").get("senderGeography"), geo), builder.equal(r

我正试图在我的项目中实现这一点:

        Specification<Delivery> shipmentSpec = ((root, query, builder) ->
                builder.or(builder.equal(root.join("entries").get("shipment").get("senderGeography"), geo),
                           builder.equal(root.join("entries").get("shipment").get("receiverGeography"), geo)));

        Specification<Delivery> collectSpec = ((root, query, builder) ->
               builder.equal(root.join("entries").get("collect").get("geography"), geo));

        repository.findAll(Specification.where(shipmentSpec).or(collectSpec);
输入实体具有以下字段:

@ManyToOne
@JoinColumn(name = "SHIPMENT_ID")
private Shipment shipment;

@ManyToOne
@JoinColumn(name = "COLLECT_ID")
private Collect collect;
其中一个字段始终为空,但不能同时为两个字段

发货和收款实体具有以下字段:

@ManyToOne(optional = false)
@JoinColumn(name = "GEOGRAPHY_ID", nullable = false)
private Geography geography;
(装运有2个地理位置)

我需要一个选项,以返回所有交付实体,其中有在其条目装运或收取指定的地理位置

谢谢

已更新。

我尝试使用@Query获取实体,但其行为与规范方法相同,返回空列表:

@Query("select d from Delivery d, Entry e where e.delivery.id = d.id " +
        "and (e.shipment.senderGeography = ?1 or e.shipment.receiverGeography = ?1 or e.collect.geography = ?1)")
List<Delivery> findByGeography(Geography geo);
@Query(“从交付d中选择d,输入e,其中e.Delivery.id=d.id”+
“和(e.shipping.senderGeography=?1或e.shipping.receiverGeography=?1或e.collect.geography=?1)”)
列出发现的地理(地理);
只有当我在查询中留下
(e.shipping.senderGeography=-1或e.shipping.receiverGeography=-1)
e.collect.geography=-1
子句时,它才起作用。
但不是两者都有。

如果您永远不会将两个值都设为null,并且需要所有行都具有指定的一个值,那么为什么不能选择所有行呢?您能否澄清
repository.findAll(Specification.where(shipmentSpec)或(Specification.where(collectSpec))
不适用于您或确实适用于您?另外,您是否可以显示请求时
shipmentSpec
collectSpec
中的内容?@ayrton如何使用规范来实现这一点?问题是,如果我这样写,它不会返回任何内容:builder.or(builder.equal(root.join(“条目”).get(“shipping”).get(“senderGeography”),geo,builder.equal(root.join(“条目”).get(“collect”).get(“geography”),geo),builder.equal(root.join(“条目”).get(“collect”).get(“geography”),geo)@Dmytro Chasovskyi Nope.repository.findAll(Specification.where(shipmentSpec).或(Specification.where(collectSpec)))也不返回任何内容。我更新了问题。
@Query("select d from Delivery d, Entry e where e.delivery.id = d.id " +
        "and (e.shipment.senderGeography = ?1 or e.shipment.receiverGeography = ?1 or e.collect.geography = ?1)")
List<Delivery> findByGeography(Geography geo);