zoukankan      html  css  js  c++  java
  • Jpa自定义查询报错(Failed to convert from type [java.lang.Object[]] to type)

    Jpa自定义查询报错

    问题背景

    今天遇到一个奇怪的报错“Failed to convert from type [java.lang.Object[]] to type”,这个报错,百度上也是很少的,恰恰是这样的问题,引起我了解决的欲望。先看看报错:

    org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.Object[]] to type [org.microservice.tcbj.yytsg.checksys.entity.Wicket] for value '{1, 7, C1, 1, 7, 1}'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Integer] to type [org.microservice.tcbj.yytsg.checksys.entity.Wicket]
    	at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:46)
    	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:191)
    	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:174)
    	at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:108)
    	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:136)
    	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:125)
    	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:590)
    	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:578)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    	at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvo
    

    在网上找了很多解决方案,多是要改变Springboot的配置,然而给便配置我肯定是不愿意的,于是经过千辛万苦,终于找到了解决方案。
    出现该错误的原因可能是你在当前的Repository里面,查询了其他的实体,例如你在UserRepository extends JpaRepository<UserEntity,Integer>里面去自定义了一个查询,该查询返回的实体是CarEntity,那就会报这样的转换错误,每个实体要都要有一个对应的XXXRepository来执行CRUD操作的。实体Entity跟Repository层内容要对应,解决方案就是将这个自定义查询剪切到对应的Repository里面。

  • 相关阅读:
    记事本02
    助人快乐:笔记本连网
    高性能 架构实例 学习笔记
    食.运动.阅读
    The server name ... address could not be resolved
    Mysql 远程访问
    CSS布局 UI 学习笔记
    MySql 修改root密码
    C#:String类型中的CharAt 方法
    La_Lb_Lc
  • 原文地址:https://www.cnblogs.com/tian874540961/p/10188800.html
Copyright © 2011-2022 走看看