簡體   English   中英

無法從類型 [java.util.LinkedHashSet<!--?--> ] 輸入 [java.util.Set<java.lang.long> ]</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.RELEASEJava 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);

不兼容的類型:不存在類型變量 F、T 的實例,因此 java.util.Collection<t> 符合 java.util.Set <java.lang.long< div><div id="text_translate"><p> 我正在嘗試將ComplexItem列表轉換為它們對應的 ID Long列表。 但是即使在使用(Collection&lt;ComplexItem&gt;)對getCollection()調用進行類型轉換后,也不會出現上述錯誤 go</p><pre> Set&lt;Long&gt; ids = Collections2.transform( getComplexItems(), new Function&lt;ComplexItem, Long&gt;() { @Override public Long apply(final ComplexItem item) { return item.id; } })); public List&lt;ComplexItem&gt; getComplexItems() {.............. }</pre> </div></java.lang.long<></t>

[英]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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 不兼容的類型:不存在類型變量 F、T 的實例,因此 java.util.Collection<t> 符合 java.util.Set <java.lang.long< div><div id="text_translate"><p> 我正在嘗試將ComplexItem列表轉換為它們對應的 ID Long列表。 但是即使在使用(Collection&lt;ComplexItem&gt;)對getCollection()調用進行類型轉換后,也不會出現上述錯誤 go</p><pre> Set&lt;Long&gt; ids = Collections2.transform( getComplexItems(), new Function&lt;ComplexItem, Long&gt;() { @Override public Long apply(final ComplexItem item) { return item.id; } })); public List&lt;ComplexItem&gt; getComplexItems() {.............. }</pre> </div></java.lang.long<></t> 無法將 Spring JPA 從類型 [java.lang.String] 轉換為類型 [java.lang.Long]? MappingException:無法確定java.util.Set的類型 基本的JPA問題:“無法確定類型:java.util.Set” 無法確定:java.util.Set的類型,在表中 hibernate MappingException:無法確定類型:java.util.Set 無法在 SPRING 中將類型“java.lang.String”的值轉換為所需的類型“java.lang.Long” &quot;message&quot;: &quot;無法從類型 [java.lang.String] 轉換為類型 [java.lang.Long] 以獲取值 &#39;count&#39;;對於輸入字符串:\\&quot;count\\&quot;&quot; Spring NumberFormatException:無法將類型&#39;java.lang.String&#39;的值轉換為所需的類型&#39;java.lang.Long Spring JPAF無法將值“為什么?”從類型[java.lang.String]轉換為類型[java.lang.Long]。
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM