-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Generics problem; ...ClassCastException: java.lang.String
PostPosted: Sun Jan 08, 2006 12:15 pm 
Newbie

Joined: Tue Jan 03, 2006 3:44 pm
Posts: 3
Hello,

I'm having a problem with my Hibernate/Spring application, getting the following error while trying to display a Hibernate persisted pojo:

Code:
   ERROR: Invalid property 'id' of bean class [ro.crispico.gioppi.model.Driver]: Getter for property 'id' threw exception; nested exception is java.lang.reflect.InvocationTargetException: null
   org.springframework.beans.InvalidPropertyException: Invalid property 'id' of bean class [ro.crispico.gioppi.model.Driver]: Getter for property 'id' threw exception; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:657)
   at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:643)
   at org.springframework.validation.BindException.getFieldValue(BindException.java:333)
   at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:117)
   at org.springframework.web.servlet.tags.BindTag.doStartTagInternal(BindTag.java:115)
   at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:68)
   at org.apache.jsp.views.driverForm_jsp._jspService(org.apache.jsp.views.driverForm_jsp:186)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at ro.crispico.gioppi.web.MessageFilter.doFilter(MessageFilter.java:36)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
   at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
   at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
   at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
   at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:97)
   at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
   at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:928)
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:705)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
   at org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
   at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at ro.crispico.gioppi.web.MessageFilter.doFilter(MessageFilter.java:36)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
   at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.ClassCastException: java.lang.String
   at ro.crispico.gioppi.model.Driver.getId(Driver.java:29)
   at ro.crispico.gioppi.model.Driver.getId(Driver.java:1)
   ... 52 more


I think the problem consits in the fact that I use generics, like this:

Code:
public abstract class Entity<ID extends Serializable>            {

   private ID id;

   public ID getId( ) {
      return id;
   }

   public void setId( ID id ) {
      this.id = id;
   }
...


and my Driver class:

Code:
/**
* @author Cristi
* @hibernate.class lazy="false"
*/
public class Driver extends Entity<Long> {
...

   /**
    * @hibernate.id generator-class="native" type="java.lang.Long" unsaved-value="0"
    */
   public Long getId( ) {
      return super.getId();
   }


If I change the generic ID type into Long (Entity class), the error doesn't appear any more.

Thank you,
Cristian.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 08, 2006 2:43 pm 
Beginner
Beginner

Joined: Sat Dec 17, 2005 1:24 pm
Posts: 42
Location: Berlin, Germany
Hi Cristian!

Looking at your stacktrace...
Code:
   [...]
   at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:657)
   at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:643)
   at org.springframework.validation.BindException.getFieldValue(BindException.java:333)
   at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:117)
   [...]

... this looks more like a problem in the spring binding of the parameters passed in the HTTP-POST (in fact I do not see a single Hibernate class in the stack trace).

If this really is the case, you may want to check the spring documentation regarding custom PropertyEditors and/or ask in the Spring forum.

All the best,

René


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.