Spring MVC Failed to convert property value of type 'java.lang.Integer' -
i have 2 entities, 1 of have composit primary key(id, version), version manytoone link entity(uchastokversion) field id.
@entity @table(name = "uchastok_versions",schema="tb") public class uchastokversion { @id @generatedvalue(strategy = generationtype.identity) @column(name = "id") private integer id; @column(name = "date_activate", columndefinition="date unique") @datetimeformat(pattern="dd.mm.yyyy") @temporal(temporaltype.date) private date dateactivate; @transient private list<uchastok> uchastki;
@entity @idclass(uchastokid.class) @table(name = "uchastki", schema = "tb") public class uchastok implements serializable{ /** * */ private static final long serialversionuid = 1l; @id @column(name = "id", unique = false, nullable = false) private integer id; @column(name = "name") private string name; @id @manytoone(targetentity=uchastokversion.class,fetch = fetchtype.lazy) @joincolumn(name = "id_version", nullable = false,referencedcolumnname="id") private uchastokversion version;
public class uchastokid implements serializable { private static final long serialversionuid = 343l; private int id; private uchastokversion version; public uchastokid() { } public int getid() { return id; } public void setid(int id) { this.id = id; } public uchastokversion getversion() { return version; } public void setversion(uchastokversion version) { this.version = version; } @override public int hashcode() { return this.id + this.version.getid(); } @override public boolean equals(object obj) { if (obj instanceof uchastokid) { uchastokid placeid = (uchastokid) obj; return (placeid.id == this.id) && (placeid.version.getid() == this.version.getid()); } return false; } }
public uchastokversion create(uchastokversion record) { try { repository.saveandflush(record); return saveuchastki(record); } catch (exception e) { logger.error("create uchastokversion error ", e); return null; } } private uchastokversion saveuchastki(uchastokversion uchastokversion){ (uchastok iterable_element : uchastokversion.getuchastki()) { iterable_element.setversion(uchastokversion); uchastokservice.create(iterable_element); } return repository.findbyid(uchastokversion.getid()); }
when try run code have exception.
hibernate: insert tb.uchastok_versions (date_activate) values (?) hibernate: select nextval('seq_uchastok_id')::int 13:50:23,121 error http-bio-8080-exec-18 uchastokversionserviceimpl:create:48 - create uchastokversion error org.springframework.beans.conversionnotsupportedexception: failed convert property value of type 'java.lang.integer' required type 'ru.crtc.arlm.model.entity.tb.uchastokversion' property 'version'; nested exception java.lang.illegalstateexception: cannot convert value of type [java.lang.integer] required type [ru.crtc.arlm.model.entity.tb.uchastokversion] property 'version': no matching editors or conversion strategy found @ org.springframework.beans.beanwrapperimpl.convertifnecessary(beanwrapperimpl.java:473) @ org.springframework.beans.beanwrapperimpl.convertforproperty(beanwrapperimpl.java:509) @ org.springframework.beans.beanwrapperimpl.setpropertyvalue(beanwrapperimpl.java:1115) @ org.springframework.beans.beanwrapperimpl.setpropertyvalue(beanwrapperimpl.java:898) @ org.springframework.data.jpa.repository.support.jpametamodelentityinformation$directfieldaccessfallbackbeanwrapper.setpropertyvalue(jpametamodelentityinformation.java:297) @ org.springframework.data.jpa.repository.support.jpametamodelentityinformation$identifierderivingdirectfieldaccessfallbackbeanwrapper.setpropertyvalue(jpametamodelentityinformation.java:340) @ org.springframework.data.jpa.repository.support.jpametamodelentityinformation.getid(jpametamodelentityinformation.java:124) @ org.springframework.data.repository.core.support.abstractentityinformation.isnew(abstractentityinformation.java:51) @ org.springframework.data.jpa.repository.support.jpametamodelentityinformation.isnew(jpametamodelentityinformation.java:191) @ org.springframework.data.jpa.repository.support.simplejparepository.save(simplejparepository.java:368) @ org.springframework.data.jpa.repository.support.simplejparepository.saveandflush(simplejparepository.java:383) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:601) @ org.springframework.data.repository.core.support.repositoryfactorysupport$queryexecutormethodinterceptor.executemethodon(repositoryfactorysupport.java:358) @ org.springframework.data.repository.core.support.repositoryfactorysupport$queryexecutormethodinterceptor.invoke(repositoryfactorysupport.java:343) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.transaction.interceptor.transactioninterceptor$1.proceedwithinvocation(transactioninterceptor.java:98) @ org.springframework.transaction.interceptor.transactionaspectsupport.invokewithintransaction(transactionaspectsupport.java:262) @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:95) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.dao.support.persistenceexceptiontranslationinterceptor.invoke(persistenceexceptiontranslationinterceptor.java:136) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.data.jpa.repository.support.lockmoderepositorypostprocessor$lockmodepopulatingmethodintercceptor.invoke(lockmoderepositorypostprocessor.java:92) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.interceptor.exposeinvocationinterceptor.invoke(exposeinvocationinterceptor.java:92) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:207) @ $proxy567.saveandflush(unknown source) @ ru.crtc.arlm.service.tb.uchastokserviceimpl.create(uchastokserviceimpl.java:64) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:601) @ org.springframework.aop.support.aoputils.invokejoinpointusingreflection(aoputils.java:317) @ org.springframework.aop.framework.reflectivemethodinvocation.invokejoinpoint(reflectivemethodinvocation.java:190) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:157) @ org.springframework.transaction.interceptor.transactioninterceptor$1.proceedwithinvocation(transactioninterceptor.java:98) @ org.springframework.transaction.interceptor.transactionaspectsupport.invokewithintransaction(transactionaspectsupport.java:262) @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:95) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:207) @ $proxy573.create(unknown source) @ ru.crtc.arlm.service.tb.uchastokversionserviceimpl.saveuchastki(uchastokversionserviceimpl.java:56) @ ru.crtc.arlm.service.tb.uchastokversionserviceimpl.create(uchastokversionserviceimpl.java:46) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:601) @ org.springframework.aop.support.aoputils.invokejoinpointusingreflection(aoputils.java:317) @ org.springframework.aop.framework.reflectivemethodinvocation.invokejoinpoint(reflectivemethodinvocation.java:190) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:157) @ org.springframework.transaction.interceptor.transactioninterceptor$1.proceedwithinvocation(transactioninterceptor.java:98) @ org.springframework.transaction.interceptor.transactionaspectsupport.invokewithintransaction(transactionaspectsupport.java:262) @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:95) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:207) @ $proxy574.create(unknown source) @ ru.crtc.arlm.controller.tb.tbnsicontroller.saveuchastokversion(tbnsicontroller.java:89) @ ru.crtc.arlm.controller.tb.tbnsicontroller$$fastclassbycglib$$aad442cd.invoke(<generated>) @ org.springframework.cglib.proxy.methodproxy.invoke(methodproxy.java:204) @ org.springframework.aop.framework.cglibaopproxy$cglibmethodinvocation.invokejoinpoint(cglibaopproxy.java:713) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:157) @ org.springframework.aop.interceptor.exposeinvocationinterceptor.invoke(exposeinvocationinterceptor.java:92) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.framework.cglibaopproxy$dynamicadvisedinterceptor.intercept(cglibaopproxy.java:646) @ ru.crtc.arlm.controller.tb.tbnsicontroller$$enhancerbycglib$$ca110f66.saveuchastokversion(<generated>) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:601) @ org.springframework.web.method.support.invocablehandlermethod.invoke(invocablehandlermethod.java:214) @ org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:132) @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:104) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:748) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:689) @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:83) @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:945) @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:876) @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:931) @ org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:833) @ javax.servlet.http.httpservlet.service(httpservlet.java:647) @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:807) @ javax.servlet.http.httpservlet.service(httpservlet.java:728) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:305) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:88) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:108) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:243) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.springframework.orm.jpa.support.openentitymanagerinviewfilter.dofilterinternal(openentitymanagerinviewfilter.java:177) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:108) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:243) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.access.intercept.filtersecurityinterceptor.invoke(filtersecurityinterceptor.java:118) @ org.springframework.security.web.access.intercept.filtersecurityinterceptor.dofilter(filtersecurityinterceptor.java:84) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.access.exceptiontranslationfilter.dofilter(exceptiontranslationfilter.java:113) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.session.sessionmanagementfilter.dofilter(sessionmanagementfilter.java:103) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.authentication.anonymousauthenticationfilter.dofilter(anonymousauthenticationfilter.java:113) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.servletapi.securitycontextholderawarerequestfilter.dofilter(securitycontextholderawarerequestfilter.java:154) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.savedrequest.requestcacheawarefilter.dofilter(requestcacheawarefilter.java:45) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.authentication.abstractauthenticationprocessingfilter.dofilter(abstractauthenticationprocessingfilter.java:199) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.authentication.logout.logoutfilter.dofilter(logoutfilter.java:110) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.context.request.async.webasyncmanagerintegrationfilter.dofilterinternal(webasyncmanagerintegrationfilter.java:50) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:108) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.context.securitycontextpersistencefilter.dofilter(securitycontextpersistencefilter.java:87) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.filterchainproxy.dofilterinternal(filterchainproxy.java:192) @ org.springframework.security.web.filterchainproxy.dofilter(filterchainproxy.java:160) @ org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy.java:344) @ org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:261) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:243) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:222) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:123) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:502) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:171) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:99) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:953) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:118) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:408) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1023) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:589) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:310) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1110) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:603) @ java.lang.thread.run(thread.java:722) caused by: java.lang.illegalstateexception: cannot convert value of type [java.lang.integer] required type [ru.crtc.arlm.model.entity.tb.uchastokversion] property 'version': no matching editors or conversion strategy found @ org.springframework.beans.typeconverterdelegate.convertifnecessary(typeconverterdelegate.java:267) @ org.springframework.beans.beanwrapperimpl.convertifnecessary(beanwrapperimpl.java:458) ... 137 more
my pom.xml.
<name>arlm maven webapp</name> <url>http://maven.apache.org</url> <properties> <jdk.version>1.7</jdk.version> <spring.version>4.0.0.release</spring.version> <org.springframework-security-version>3.2.0.release</org.springframework-security-version> <org.aspectj-version>1.6.11</org.aspectj-version> <slf4j.version>1.7.5</slf4j.version> <jackson.version>1.9.12</jackson.version> <hibernate.version>4.3.4.final</hibernate.version> <querydsl.version>3.3.1</querydsl.version> <spring-data-jpa.version>1.5.1.release</spring-data-jpa.version> </properties>
i don't know reason of exception.
update 1: found combination of dependencies, work fine.
<hibernate.version>4.2.8.final</hibernate.version> <spring-data-jpa.version>1.2.0.release</spring-data-jpa.version>
if change spring-data-jpa 1.4.3 version, exception appear. can resolve problem?
user @responsebody
annotation @requestmapping
below -
@requestmapping(value = "/test", method = requestmethod.get) @responsebody public int testit() { return 1; }
Comments
Post a Comment