Announcement Announcement Module
Collapse
No announcement yet.
Problem withTypeMismatchException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem withTypeMismatchException

    Hi,

    I'm trying to use HibernateDaoSupport and HibernateInterceptor in a web application. When I try to set a DAO class in my BussinesFacade implementation a have a TypeMismatchException. What could be wrong ?

    tks's
    Diego

    --- applicationContext.xml ---
    ....
    <bean id="myHibernateInterceptor" class="org.springframework.orm.hibernate.Hibernate Interceptor">
    <property name="sessionFactory">
    <ref bean="mySessionFactory"/>
    </property>
    </bean>

    <bean id="customerDaoTarget" class="hotel.model.dao.hibernate.CustomerDaoImpl">
    <property name="sessionFactory">
    <ref bean="mySessionFactory"/>
    </property>
    </bean>

    <bean id="customerDao" class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="proxyInterfaces">
    <value>hotel.dao.CustomerDao</value>
    </property>
    <property name="interceptorNames">
    <list>
    <value>myHibernateInterceptor</value>
    <value>customerDaoTarget</value>
    </list>
    </property>
    </bean>

    <bean id="hotelFacade" class="hotel.domain.logic.HotelFacadeImpl">
    <property name="customerDao">
    <ref bean="customerDaoTarget"/>
    </property>
    </bean>
    -- the classes -----
    Code:
    public class CustomerDaoImpl extends HibernateDaoSupport implements CustomerDao
    &#123; ..... &#125;
    
    public class HotelFacadeImpl implements HotelFacade
    &#123;
    CustomerDao customerDao = null;
    
    public void setCustomerDao&#40;CustomerDao customerDao&#41;
    &#123;
    customerDao = this.customerDao;
    &#125;
    .........
    &#125;
    ---- Exception during startup ------


    21:10:01.472 INFO [main] org.springframework.beans.factory.support.Abstract BeanFactory.destroySingletons(AbstractBeanFactory. java:409) >18> Destroying singletons in factory {org.springframework.beans.factory.support.Default ListableBeanFactory defining beans [myDataSource,mySessionFactory,myHibernateIntercept or,myReservationDaoTarget,customerDaoTarget,myRese rvationDao,customerDao,hotelFacade]; Root of BeanFactory hierarchy}
    21:10:01.492 INFO [main] org.springframework.orm.hibernate.LocalSessionFact oryBean.destroy(LocalSessionFactoryBean.java:625) >21> Closing Hibernate SessionFactory
    21:10:01.492 INFO [main] net.sf.hibernate.impl.SessionFactoryImpl.close(Ses sionFactoryImpl.java:531) >22> closing
    21:10:01.492 ERROR! [main] org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:108) >12> Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'hotelFacade' defined in resource [/WEB-INF/applicationContext.xml] of ServletContext: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptions Exception: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [hotel.model.dao.hibernate.CustomerDaoImpl] to required type [hotel.dao.CustomerDao] for property 'customerDao']
    PropertyAccessExceptionsException (1 errors)
    org.springframework.beans.TypeMismatchException: Failed to convert property value of type [hotel.model.dao.hibernate.CustomerDaoImpl] to required type [hotel.dao.CustomerDao] for property 'customerDao'
    at org.springframework.beans.BeanWrapperImpl.doTypeCo nversionIfNecessary(BeanWrapperImpl.java:909)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:673)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:588)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:720)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:747)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:736)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:797)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:637)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:271)

    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:208)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:204)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:136)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:230)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:284)
    at org.springframework.web.context.support.XmlWebAppl icationContext.refresh(XmlWebApplicationContext.ja va:131)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:156)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:97)
    at org.springframework.web.context.ContextLoaderServl et.init(ContextLoaderServlet.java:80)
    at javax.servlet.GenericServlet.init(GenericServlet.j ava:256)

  • #2
    It looks like your code should be correct. (you're passing an implementation while expecting an implemented interface)
    However, you're configuring your facade with the target instead of the proxied object. Can you check how it behave when using the following piece of code :
    Code:
    <bean id="hotelFacade" class="hotel.domain.logic.HotelFacadeImpl">
    <property name="customerDao">
    <ref bean="customerDaoTarget"/>
    </property>
    </bean>
    HTH

    Olivier

    Comment


    • #3
      However, you're configuring your facade with the target instead of the proxied object.
      I've already test using the proxied object and the result was similar .


      Code:
      ...
      <bean id="customerDao" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="proxyInterfaces">
          <value>hotel.dao.CustomerDao</value>
        </property>
        <property name="interceptorNames"> 
          <list>
            <value>myHibernateInterceptor</value>
            <value>customerDaoTarget</value>     
          </list>
        </property>
      </bean>
      
      <bean id="hotelFacade" class="hotel.domain.logic.HotelFacadeImpl">
      	<property name="customerDao">
      		<ref bean="customerDao"/>
      	</property>
      </bean>
      10:17:20.427 ERROR! [main] org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:108) >12> Context initialization failed
      org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'hotelFacade' defined in resource [/WEB-INF/applicationContext.xml] of ServletContext: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptions Exception: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy1] to required type [hotel.dao.CustomerDao] for property 'customerDao']
      PropertyAccessExceptionsException (1 errors)
      org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy1] to required type [hotel.dao.CustomerDao] for property 'customerDao'

      Comment


      • #4
        I'm a bit clueless on this one ..
        Could you make your customerDao property in the facade accepting a mere Object and in the setter, dump in a log the implemented interfaces (object.getClass().getInterfaces() returns an array of Class you can write into a stream). It could be a problem of synchronization of source code or packages mismatch..

        Olivier

        Comment


        • #5
          Oliver,

          I've made some changes as you suggested. Firts of all, the code below works ok :
          Code:
          import hotel.dao.CustomerDao;
          import hotel.model.dao.hibernate.CustomerDaoImpl;
          
          public class Test
          &#123;
              public static void main&#40;String&#91;&#93; args&#41;
              &#123;        
                  CustomerDaoImpl customerDao = new CustomerDaoImpl&#40;&#41;;
                  CustomerDao testcustomerDao = &#40;CustomerDao&#41;customerDao;
              &#125;
          &#125;
          Changing the facade to accept Object, works too:
          Code:
          package hotel.domain.logic;
          
          import hotel.dao.CustomerDao;
          import hotel.domain.Customer;
          
          import java.util.Date;
          import java.util.List;
          
          public class HotelFacadeImpl implements HotelFacade
          &#123;
              Object customerDao;
          
              public void setCustomerDao&#40;Object customerDao&#41;
              &#123;
                 this.customerDao = customerDao;
              &#125;
          ...
          &#125;
          But if i change to use a explicit cast :
          Code:
          package hotel.domain.logic;
          
          import hotel.dao.CustomerDao;
          import hotel.domain.Customer;
          
          import java.util.Date;
          import java.util.List;
          
          public class HotelFacadeImpl implements HotelFacade
          &#123;
              CustomerDao customerDao;
          
              public void setCustomerDao&#40;Object customerDao&#41;
              &#123;
                 this.customerDao = &#40;CustomerDao&#41;customerDao;
              &#125;
          ...
          &#125;
          I have the Exception:

          13:56:25.198 ERROR! [main] org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:108) >12> Context initialization failed
          org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'hotelFacade' defined in resource [/WEB-INF/applicationContext.xml] of ServletContext: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptions Exception: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [hotel.model.dao.hibernate.CustomerDaoImpl] to required type [java.lang.Object] for property 'customerDao'; nested exception is java.lang.ClassCastException: null]
          PropertyAccessExceptionsException (1 errors)
          org.springframework.beans.TypeMismatchException: Failed to convert property value of type [hotel.model.dao.hibernate.CustomerDaoImpl] to required type [java.lang.Object] for property 'customerDao'; nested exception is java.lang.ClassCastException: null
          java.lang.ClassCastException
          at hotel.domain.logic.HotelFacadeImpl.setCustomerDao( HotelFacadeImpl.java:26)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:324)
          at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:684)
          at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:588)
          at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:720)
          at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:747)
          at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:736)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:797)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:637)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:271)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:208)
          at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:204)
          at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:136)
          at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:230)

          I've put some break points to check the objects:
          (Object customerDao)
          'hotel.model.dao.hibernate.CustomerDaoImpl@1c0bee6 '
          customerDao.getClass().getInterfaces() : 'interface hotel.dao.CustomerDao'

          Comment


          • #6
            I'm even more clueless :/
            There must be something really basic we're missing there. Could you send me this piece of code (or preferably the smallest version which trigger this problem) so that I can have a look directly ?

            Olivier

            Comment


            • #7
              I've isolated the piece of the application where the problem occurs and I've had a surprise: If the application wasn't start as a web app, everything works fine.
              But if a start as a web app (wich is the way I would like) this stupid error comes again.

              I'm using Jetty 5.0.0 launching from Eclipse 3.0 using the jetty launcher plugin .

              In my last change I don't use the interface:

              Code:
              public class HotelFacadeImpl implements HotelFacade
              &#123;
                  CustomerDaoImpl customerDao;
              
                  public void setCustomerDao&#40;CustomerDaoImpl customerDao&#41; 
                  &#123;
                     this.customerDao = customerDao;
                  &#125;
                ...
              &#125;
              That's the result :
              PropertyAccessExceptionsException (1 errors)
              org.springframework.beans.TypeMismatchException: Failed to convert property value of type [hotel.model.dao.hibernate.CustomerDaoImpl] to required type [hotel.model.dao.hibernate.CustomerDaoImpl] for property 'customerDao'
              ...
              :shock:

              Comment


              • #8
                Originally posted by fsadiego
                PropertyAccessExceptionsException (1 errors)
                org.springframework.beans.TypeMismatchException: Failed to convert property value of type [hotel.model.dao.hibernate.CustomerDaoImpl] to required type [hotel.model.dao.hibernate.CustomerDaoImpl] for property 'customerDao'
                ...
                For me that looks like a class loading issue. Since Jetty surely uses its own classloaders there must be a conflict somewhere. It seems that some classes are loaded by different classloaders. Does it work with jetty outside of eclipse?

                Regards,
                Andreas

                Comment


                • #9
                  I don't know exactly what was hapennig but I rebuild all the application, cleaning all the old classes and finally inside Jetty everything works fine.

                  Tks Andreas and Olivier


                  Diego

                  Comment


                  • #10
                    Quite a ways behind the 8 ball here but I was having a similar problem, found this thread and it helped me to fix the problem. I thought I'd give a bit more detail for the benefit of anyone else who might come across this discussion thread.

                    For me, it was definitely a ClassLoader issue. I was deploying my webapp with the Spring jar files in its WEB-INF/lib directory but I decided to add them to the Application Server's lib directory instead. That was when the TypeMismatchException started occurring. The problem was that I hadn't removed the jars from my webapp so the App Server was loading them from 2 different places.

                    Comment

                    Working...
                    X