码迷,mamicode.com
首页 > 编程语言 > 详细

Jpa自定义查询报错(Failed to convert from type [java.lang.Object[]] to type)

时间:2018-12-28 10:57:02      阅读:583      评论:0      收藏:0      [点我收藏+]

标签:遇到   rac   解决   data   exec   aspect   failed   aop   pre   

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里面。

Jpa自定义查询报错(Failed to convert from type [java.lang.Object[]] to type)

标签:遇到   rac   解决   data   exec   aspect   failed   aop   pre   

原文地址:https://www.cnblogs.com/tian874540961/p/10188800.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!