[英]Failed to convert from type [java.util.LinkedHashSet<?>] to type [java.util.Set<java.lang.Long>]
I'm currently updating my project from Java 8 with Springboot 1.5.9.RELEASE
to Java 11 with Springboot 2.2.7.RELEASE
.我目前正在将我的项目从
Java 8 with Springboot 1.5.9.RELEASE
到Java 11 with Springboot 2.2.7.RELEASE
。 I was able to make it run although when I was doing the testing, one query of it does not work anymore.尽管在我进行测试时,我能够让它运行,但它的一个查询不再起作用。 It's throwing a
Failed to convert from type [java.util.LinkedHashSet<?>] to type [java.util.Set<java.lang.Long>]... nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [project.Param] to type [java.lang.Long]
.它抛出一个
Failed to convert from type [java.util.LinkedHashSet<?>] to type [java.util.Set<java.lang.Long>]... nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [project.Param] to type [java.lang.Long]
。 The project also builds perfectly and does not have any warnings of deprecated items on the classes stated below.该项目也可以完美构建,并且在下面所述的类中没有任何已弃用项目的警告。
This is how I call it in my service:这就是我在服务中的称呼:
Set<Long> ids = ParamRepository.findIdByCampaign(campaign);
Param.java参数 java
@Entity
@Table(name = "PARAM")
public class Param implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ID_PARAM", updatable = false, nullable = false)
private Long id;
@ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
@JoinColumn(name = "ID_CAMPAIGN", nullable = false)
private Campaign campaign;
ParamRepository.java参数库.java
@Repository
public interface ParamRepository extends JpaRepository<Param, Long> {
Set<Long> findIdByCampaign(Campaign campaign);
}
I've tried changing the JpaRepository<Param, Long> to JpaRepository<Param, Serializable> since, besides the findByCampaign query, it also involves other native queries.我尝试将JpaRepository<Param, Long>更改为JpaRepository<Param, Serializable>因为除了 findByCampaign 查询外,它还涉及其他本机查询。 Although it doesn't make sense since it was working before so I'm quite not sure what to check next.
虽然它没有意义,因为它之前工作过,所以我不太确定接下来要检查什么。
Any other thoughts on why the error occurs or to what I should check further?关于错误发生的原因或我应该进一步检查的内容的任何其他想法? Thank you in advance!
先感谢您!
findIdByCampaign
will return Collection of Entity means Param
not Long
, you should select the id
only to get Set of Long. findIdByCampaign
将返回实体集合意味着Param
不是Long
,你应该 select id
只得到长的集合。
To select only id, a way can be using JPQL with @Query
annotation.对于 select 只有 id,一种方法可以使用带有
@Query
注释的 JPQL。
@Query("Select p.id from Param p where p.campaign = :campaign")
Set<Long> findIdByCampaign(@Param("campaign") Campaign campaign);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.