Spring错误无法将[java.lang.String]类型的值转换为所需类型 - 找不到匹配的编辑器或转换策略

时间:2014-06-24 14:39:46

标签: java spring hibernate spring-data

任何想法导致此错误的原因是什么?

我一直在阅读,我认为这与我如何声明失败的对象(即它必须被声明为接口)有关,但我不认为我正在理解究竟发生了什么。有人可以提供一个明确的解释,说明导致错误的原因以及我如何解决它。

提前致谢

2014-06-23 16:43:12,905 [main] ERROR com.abc.Author.loader.service.duplicate.myProdDuplicateAuthorService - JDUPLICATE - Error processing 198587 Author.
org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'com.abc.Author.loader.model.myProdDuplicate' for property 'myProdDuplicate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.abc.Author.loader.model.myProdDuplicate] for property 'myProdDuplicate': no matching editors or conversion strategy found
        at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:463)
        at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:494)
        at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1097)
        at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:882)
        at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation$DirectFieldAccessFallbackBeanWrapper.setPropertyValue(JpaMetamodelEntityInformation.java:290)
        at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation$IdentifierDerivingDirectFieldAccessFallbackBeanWrapper.setPropertyValue(JpaMetamodelEntityInformation.java:333)
        at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.getId(JpaMetamodelEntityInformation.java:123)
        at org.springframework.data.repository.core.support.AbstractEntityInformation.isNew(AbstractEntityInformation.java:51)
        at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.isNew(JpaMetamodelEntityInformation.java:190)
        at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:357)
        at sun.reflect.GeneratedMethodAccessor57.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:344)
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:329)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:92)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy103.save(Unknown Source)
        at com.abc.Author.loader.dao.common.myProdDuplicateDAO.storeUnequivocalMatch(myProdDuplicateDAO.java:44)
        at com.abc.Author.loader.service.duplicate.myProdDuplicateAuthorService.matchAuthor(myProdDuplicateAuthorService.java:62)
        at com.abc.Author.loader.service.duplicate.myProdDuplicateAuthorService.matchBatch(myProdDuplicateAuthorService.java:43)
        at com.abc.Author.loader.app.myProdDuplicateMatchMain.main(myProdDuplicateMatchMain.java:18)
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.abc.Author.loader.model.myProdDuplicate] for property 'myProdDuplicate': no matching editors or conversion strategy found
        at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:264)
        at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:448)
        ... 31 

它抱怨的对象(即' myProdDuplicate')是具有大量字段的JPA实体的复合键的一部分。我设法找出问题是使用复合键,因为如果我更改复合键以使用@Embedable注释,它工作正常。

修改

@Id
@ManyToOne
@JoinColumn(name="AUTHOR_ID")
private MyProdDuplicate myProdDuplicate;

@Id
@Column(name = "title")
private String title;

错误发生在这一行(使用spring数据存储库保存到db):

authorRepository.save(listItem);

上述定义是否会突然停止工作并产生上述错误?弹簧(弹簧数据)版本升级会导致这种情况吗?

我目前正在使用Spring版本3.2.3.RELEASE和Spring数据版本1.4.2.RELEASE

0 个答案:

没有答案