[英]incompatible types: no instance(s) of type variable(s) F,T exist so that java.util.Collection<T> conforms to java.util.Set<java.lang.Long
[英]Failed to convert from type [java.util.LinkedHashSet<?>] to type [java.util.Set<java.lang.Long>]
我目前正在將我的項目從Java 8 with Springboot 1.5.9.RELEASE
到Java 11 with Springboot 2.2.7.RELEASE
。 盡管在我進行測試時,我能夠讓它運行,但它的一個查詢不再起作用。 它拋出一個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]
。 該項目也可以完美構建,並且在下面所述的類中沒有任何已棄用項目的警告。
這就是我在服務中的稱呼:
Set<Long> ids = ParamRepository.findIdByCampaign(campaign);
參數 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;
參數庫.java
@Repository
public interface ParamRepository extends JpaRepository<Param, Long> {
Set<Long> findIdByCampaign(Campaign campaign);
}
我嘗試將JpaRepository<Param, Long>更改為JpaRepository<Param, Serializable>因為除了 findByCampaign 查詢外,它還涉及其他本機查詢。 雖然它沒有意義,因為它之前工作過,所以我不太確定接下來要檢查什么。
關於錯誤發生的原因或我應該進一步檢查的內容的任何其他想法? 先感謝您!
findIdByCampaign
將返回實體集合意味着Param
不是Long
,你應該 select id
只得到長的集合。
對於 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.