【发布时间】:2020-06-15 08:41:11
【问题描述】:
我有一个存储库:MEOfferRepository
@Repository
public interface MEOfferRepository extends JpaRepository<MEOfferDetailEntity, Long> {
@Query("select carrierId, carrierName from MEOfferDetailEntity entity where "
+ "(:countryCode is null or entity.carrierGeoAreaCode =:countryCode)")
CompletableFuture<Set<MEOfferDetail>> findCarrierByCountryCode(
final @Param("countryCode") String countryCode);
}
MEOfferDetailEntity 是实体,MEOfferDetail 是该实体的投影。
如果我提供了一个有效的 countryCode 并且我从这个查询中得到了预期的结果,那么这工作正常,问题是当我将国家代码传递为 null 时。
我期待 :countryCode is null 运行,因为 null 是 null 并且查询将在没有 where 子句的情况下获取结果。
这个查询在 MySql 工作台中给出了预期的结果,但在 Spring Boot JPA 中我得到一个空集作为响应,这不应该是这种情况。
【问题讨论】:
标签: mysql spring spring-data-jpa projection