简体   繁体   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>]

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.RELEASEJava 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);

不兼容的类型:不存在类型变量 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> - 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 无法将 Spring JPA 从类型 [java.lang.String] 转换为类型 [java.lang.Long]? - Failed to convert from type [java.lang.String] to type [java.lang.Long] for Spring JPA? MappingException:无法确定java.util.Set的类型 - MappingException: Type can not be determined for java.util.Set 基本的JPA问题:“无法确定类型:java.util.Set” - Basic JPA issue: “Could not determine type for: java.util.Set” 无法确定:java.util.Set的类型,在表中 - Could not determine type for: java.util.Set, at table hibernate MappingException:无法确定类型:java.util.Set - hibernate MappingException: Could not determine type for: java.util.Set 无法在 SPRING 中将类型“java.lang.String”的值转换为所需的类型“java.lang.Long” - Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long' in SPRING &quot;message&quot;: &quot;无法从类型 [java.lang.String] 转换为类型 [java.lang.Long] 以获取值 &#39;count&#39;;对于输入字符串:\\&quot;count\\&quot;&quot; - "message": "Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'count'; For input string: \"count\"" Spring NumberFormatException:无法将类型&#39;java.lang.String&#39;的值转换为所需的类型&#39;java.lang.Long - Spring NumberFormatException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long Spring JPAF无法将值“为什么?”从类型[java.lang.String]转换为类型[java.lang.Long]。 - Spring JPAFailed to convert from type [java.lang.String] to type [java.lang.Long] for value 'Why?'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM