Announcement Announcement Module
Collapse
No announcement yet.
HibernateDaoSupport - TypeMismatchException problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HibernateDaoSupport - TypeMismatchException problem

    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 -----
    public class CustomerDaoImpl extends HibernateDaoSupport implements CustomerDao
    { ..... }

    public class HotelFacadeImpl implements HotelFacade
    {
    CustomerDao customerDao = null;

    public void setCustomerDao(CustomerDao customerDao)
    {
    customerDao = this.customerDao;
    }
    .........
    }

    ---- 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
    public void setCustomerDao(CustomerDao customerDao)
    {
    customerDao = this.customerDao;
    }
    You should replace it with
    Code:
    public void setCustomerDao&#40;CustomerDao customerDao&#41; 
    &#123; 
    this.customerDao = customerDao; 
    &#125;

    Comment


    • #3
      Failed to convert property value of type [hotel.model.dao.hibernate.CustomerDaoImpl] to required type [hotel.dao.CustomerDao] for property 'customerDao'
      are you sure that you use the correct packages?
      - hotel.model.dao.hibernate.CustomerDaoImpl
      - hotel.dao.CustomerDao
      check inside CustomerDaoImpl what package the implemented interface comes from.

      Comment


      • #4
        are you sure that you use the correct packages?
        - hotel.model.dao.hibernate.CustomerDaoImpl
        - hotel.dao.CustomerDao
        check inside CustomerDaoImpl what package the implemented interface comes from.
        The packages are correct :
        Code:
        package hotel.model.dao.hibernate;
        
        import hotel.dao.CustomerDao;
        import hotel.domain.Customer;
        import net.sf.hibernate.HibernateException;
        import net.sf.hibernate.Session;
        
        import org.springframework.orm.hibernate.SessionFactoryUtils;
        import org.springframework.orm.hibernate.support.HibernateDaoSupport;
        
        public class CustomerDaoImpl extends HibernateDaoSupport implements CustomerDao
        &#123; ... &#125;

        Comment

        Working...
        X