我正在spring boot
项目中工作。在我的JPA repository
中,我正在使用sql
本机查询并启用了分页。但是在服务层上,我得到ConvertorNotFoundException
..尝试了不同数据类型的很多次..但都徒劳。下面是我的代码类:
存储库界面
public interface ContentSongsRepository extends JpaRepository<ContentSongs,Long>{
@Query(value= "SELECT date(start_date) as DATEE, sum(case when subscription_from in ('IVR','SMS') and remarks like '%Change Song%' then 1 else 0 end) as 'song_change' from subscription group by date(start_date) \n#pageable\n",nativeQuery=true)
Page<SongChangeCount> getSongChangeCount2(Pageable page);
}
SQL查询运行正常。下面是图像。
服务层方法调用存储库
@Override
public SongChangeCountView getSongChangeCount(Pageable page) {
// TODO Auto-generated method stub
Page<SongChangeCount> songChangePageList = contantSongRepository.getSongChangeCount2(page);
List<SongChangeCount> list = songChangePageList.getContent();
Integer pageCount = songChangePageList.getTotalPages();
Long totalElement = songChangePageList.getTotalElements();
SongChangeCountView sccv = new SongChangeCountView();
sccv.setLsSongChangeCountView(list);
sccv.setPageCount(pageCount);
sccv.setTotalElement(totalElement);
return sccv;
}
SongChangeCount类
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
public class SongChangeCount implements Serializable{
private static final long serialVersionUID = -5410845856201124932L;
private Date DATEE;
private String song_change;
public SongChangeCount(Date dATEE, String song_change) {
DATEE = dATEE;
this.song_change = song_change;
}
public Date getDATEE() {
return DATEE;
}
public void setDATEE(Date dATEE) {
DATEE = dATEE;
}
public String getSong_change() {
return song_change;
}
public void setSong_change(String song_change) {
this.song_change = song_change;
}
}
每次运行以下异常代码时,都会出现:
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.sql.Date] to type [com.crbt.api.services.bean.SongChangeCount]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:324) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:206) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.core.convert.support.ArrayToObjectConverter.convert(ArrayToObjectConverter.java:66) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:37) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:203) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:187) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.data.repository.query.ResultProcessor$ProjectingConverter.convert(ResultProcessor.java:288) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.data.repository.query.ResultProcessor$ChainingConverter$1.convert(ResultProcessor.java:210) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.data.repository.query.ResultProcessor$ChainingConverter.convert(ResultProcessor.java:221) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.data.domain.Chunk.getConvertedContent(Chunk.java:168) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.data.domain.PageImpl.map(PageImpl.java:104) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.data.domain.PageImpl.map(PageImpl.java:28) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.data.repository.query.ResultProcessor.processResult(ResultProcessor.java:143) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:121) ~[spring-data-jpa-1.11.9.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:106) ~[spring-data-jpa-1.11.9.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:499) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:477) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:56) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133) ~[spring-data-jpa-1.11.9.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57) ~[spring-data-commons-1.13.9.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at com.sun.proxy.$Proxy186.getSongChangeCount2(Unknown Source) ~[na:na]
at com.crbt.api.services.service.ContentManagerServiceImpl.getSongChangeCount(ContentManagerServiceImpl.java:433) ~[classes/:na]
at com.crbt.api.services.controller.ContentManagerController.songChangeCounts(ContentManagerController.java:80) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
有人可以告诉我这里出了什么问题吗。我尝试将Date数据类型更改为java date,但仍然不能解决我的问题。