Failed to convert property value of type 'java.lang.String' to required type 'com.googlecode.objectify.Ref'

3,400 views
Skip to first unread message

Phuong Nguyen

unread,
Aug 15, 2013, 10:32:06 PM8/15/13
to objectify...@googlegroups.com
Now I'm using Objectity4 rc1 and Spring MVC 3.1

I have an entity "Country"

@Entity(name="Country")

@Cache

@NoArgsConstructor

@EqualsAndHashCode(of="countryId")

@Data

public class Country {

@Id

private Long countryId;

@Index

private String countryCode2L;//set country code in 2 letters

@Index

private String countryCode3L;//set country code in 3 letters

@Index

private int countryCodeNo;//set country code in phone number code

//@Index

//@Load 

private Ref<Continent> continentId;

@Index

private String capital;//region or city is captial

@Index

private String largestCity;// largest city 


public Long getContinentIdStr(){

return continentId.get().getContinentId();

}

}


And when I save that entity in the controller

@RequestMapping(value = "/save", method = RequestMethod.POST)

public String saveCountry(@ModelAttribute("country") Country country, @ModelAttribute CountryTrans countryTrans, HttpServletRequest request ) {

Long continentId = Long.parseLong(request.getParameter("continentId"));

logger.info("continentId.", continentId);

countryService.saveCountry(country, countryTrans, continentId);


return "redirect:/country/index";

}


And this is error

HTTP ERROR 500

Problem accessing /country/save. Reason:

 org.springframework.validation.BeanPropertyBindingResult: 1 errors Field error in object 'country' on field 'continentId': rejected value [40]; codes [typeMismatch.country.continentId,typeMismatch.continentId,typeMismatch.com.googlecode.objectify.Ref,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [country.continentId,continentId]; arguments []; default message [continentId]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'com.googlecode.objectify.Ref' for property 'continentId'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.googlecode.objectify.Ref] for property 'continentId': no matching editors or conversion strategy found]

Caused by:

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors Field error in object 'country' on field 'continentId': rejected value [40]; codes [typeMismatch.country.continentId,typeMismatch.continentId,typeMismatch.com.googlecode.objectify.Ref,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [country.continentId,continentId]; arguments []; default message [continentId]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'com.googlecode.objectify.Ref' for property 'continentId'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.googlecode.objectify.Ref] for property 'continentId': no matching editors or conversion strategy found] 	at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:110) 	at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:75) 	at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162) 	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:123) 	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100) 	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604) 	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565) 	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) 	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) 	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) 	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) 	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) 	at com.googlecode.objectify.cache.AsyncCacheFilter.doFilter(AsyncCacheFilter.java:59) 	at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:49) 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 	at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74) 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 	at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123) 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 	at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34) 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 	at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63) 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 	at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43) 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 	at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125) 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 	at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:368) 	at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:351) 	at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116) 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) 	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) 	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) 	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) 	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) 	at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:97) 	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 	at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:485) 	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 	at org.mortbay.jetty.Server.handle(Server.java:326) 	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) 	at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938) 	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755) 	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218) 	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) 	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409) 	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) 

Powered by Jetty:/


Anyone help me to fix this error please?

Jeff Schnitzer

unread,
Aug 16, 2013, 12:09:51 AM8/16/13
to objectify...@googlegroups.com
I'm no spring expert, but it looks like you're trying to make spring do some sort of reflective bean population on your model class, and spring doesn't automatically do something useful with the Ref. I can't help beyond that.

It seems a very poor idea to automatically populate your domain model classes from http parameters. See: Endless ruby security issues around "mass assignment".

Jeff


--
You received this message because you are subscribed to the Google Groups "objectify-appengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objectify-appen...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Phuong Nguyen

unread,
Aug 16, 2013, 12:55:39 AM8/16/13
to objectify...@googlegroups.com, je...@infohazard.org
Thank you for response to me.

So to fix this issue then I have to set Value field by field? Cannot pass an entity?
To unsubscribe from this group and stop receiving emails from it, send an email to objectify-appengine+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages