Spring boot 查询中的JPA似乎不返回任何结果
我正在尝试运行一个in查询(springboot+jpa+mysql)。我已经启用了调试日志,查询似乎很好,但是SpringJPA没有返回任何结果 以下是配置:Spring boot 查询中的JPA似乎不返回任何结果,spring-boot,spring-data-jpa,Spring Boot,Spring Data Jpa,我正在尝试运行一个in查询(springboot+jpa+mysql)。我已经启用了调试日志,查询似乎很好,但是SpringJPA没有返回任何结果 以下是配置: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <vers
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.23</version>
<scope>runtime</scope>
</dependency>
</dependencies>
生成的查询:
Hibernate:
select
targetingl0_.id as id1_1_,
targetingl0_.city as city2_1_,
targetingl0_.country as country3_1_,
targetingl0_.geohash as geohash4_1_,
targetingl0_.latitude as latitude5_1_,
targetingl0_.longitude as longitud6_1_,
targetingl0_.site_name as site_nam7_1_,
targetingl0_.state as state8_1_,
targetingl0_.targeting_data as targetin9_1_,
targetingl0_.targeting_location_master_id as targeti10_1_,
targetingl0_.targeting_type as targeti11_1_
from
targeting_locations targetingl0_
where
targetingl0_.targeting_location_master_id in (
?
)
2021-02-23 16:22:46.199 TRACE 28282 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [BIGINT] - [13063]
只需在存储库中将其定义为一种方法
List<TargetingLocations> findByTargetingLocationMasterIdIn(List<Long> targetingLocationMasterIds);
List findByTargetingLocationMasterIdIn(List targetingglocationmasterids);
删除@Query
,并且名称应以findBy开头。。。不是芬德尔
您想要实现的功能将由spring jpa自动实现,您是否运行了上述查询。它会返回结果吗?尝试FindAlByTargetingLocationMasterIdList而不是FindAlByTargetingLocationMasterIdIn,或者检查您是否可以尝试在中使用
而不是,并打开单个元素集合,以查看id是否确实匹配?
@Entity
@Table(name = "targeting_locations")
public class TargetingLocations {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
@Column(name = "geohash")
public String geoHash;
@Column(name = "site_name")
public String siteName;
@Column(name = "city")
public String city;
@Column(name = "country")
public String country;
@Column(name = "state")
public String state;
@Column(name = "latitude")
public Double latitude;
@Column(name = "longitude")
public Double longitude;
@Column(name = "targeting_type")
public String targetingType;
@Column(name = "targeting_data")
public String targetingData;
@Column(name = "targeting_location_master_id")
public Long targetingLocationMasterId; // ----> in query in this column
Hibernate:
select
targetingl0_.id as id1_1_,
targetingl0_.city as city2_1_,
targetingl0_.country as country3_1_,
targetingl0_.geohash as geohash4_1_,
targetingl0_.latitude as latitude5_1_,
targetingl0_.longitude as longitud6_1_,
targetingl0_.site_name as site_nam7_1_,
targetingl0_.state as state8_1_,
targetingl0_.targeting_data as targetin9_1_,
targetingl0_.targeting_location_master_id as targeti10_1_,
targetingl0_.targeting_type as targeti11_1_
from
targeting_locations targetingl0_
where
targetingl0_.targeting_location_master_id in (
?
)
2021-02-23 16:22:46.199 TRACE 28282 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [BIGINT] - [13063]
List<TargetingLocations> findByTargetingLocationMasterIdIn(List<Long> targetingLocationMasterIds);