Results 1 to 3 of 3
  1. #1
    nayal_java is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default Hibernate Spring Struts Integration Problem

    I am integrating Struts 2-Spring 3-Hibernate 4 application.

    Please suggest some solution.
    I am getting following error:

    Stacktrace

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'masterDao' defined in ServletContext resource [/WEB-INF/spring-config.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'sessionFactory' of bean class [in.nic.eservicebook.dao.MasterDaoImpl]: Bean property 'sessionFactory' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1396)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1118)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 94)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:225)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:291 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:464)
    at org.springframework.web.context.ContextLoader.conf igureAndRefreshWebApplicationContext(ContextLoader .java:384)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:283)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 111)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:4723)
    at org.apache.catalina.core.StandardContext$1.call(St andardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(St andardContext.java:5221)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'sessionFactory' of bean class [in.nic.eservicebook.dao.MasterDaoImpl]: Bean property 'sessionFactory' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:1064)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:924)
    at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(AbstractPropertyAccessor.java:7 6)
    at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(AbstractPropertyAccessor.java:5 8)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1393)
    ... 20 more



    spring-config.xml

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    
    
    <context:component-scan base-package="in.nic.eservicebook" />
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <bean id="propertyConfigurer"
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="location">
                <value>/WEB-INF/databaseConfig.properties</value>
            </property>
            </bean>
    <bean id="dataSource"  
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
            <property name="driverClassName" value="${db.driverClassName}" />  
            <property name="url" value="${db.databaseurl}" />  
            <property name="username" value="${db.username}" />  
            <property name="password" value="${db.password}" />  
        </bean>  
      
      <bean id="sessionFactory"  
            class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">  
            <property name="dataSource" ref="dataSource" />
         <property name="annotatedClasses">
    <list>
    <value>in.nic.eservicebook.pojo.Title</value>
    <value>in.nic.eservicebook.pojo.BloodGroup</value>
    <value>in.nic.eservicebook.pojo.Community</value>
    </list>
    </property>
            <property name="hibernateProperties">  
                <props>  
                    <prop key="hibernate.dialect">${hibernate.dialect}</prop>  
                    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                </props>  
            </property>  
        </bean>  
    
     
      <bean id="masterDao" class="in.nic.eservicebook.dao.MasterDaoImpl">
        <property name="sessionFactory" ref="sessionFactory" />
      </bean>
      
       <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionFactory" />
     </bean>
       
    
    </beans>
    MasterDaoImpl.java

    Java Code:
    package in.nic.eservicebook.dao;
    
    import in.nic.eservicebook.pojo.BloodGroup;
    import in.nic.eservicebook.pojo.Community;
    import in.nic.eservicebook.pojo.Title;
    import in.nic.util.HibernateUtil;
    import java.util.List;
    import org.hibernate.HibernateException;
    import org.hibernate.SessionFactory;
    
    import org.hibernate.Session;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Repository;
    @Repository("masterDao")
    public class MasterDaoImpl implements MasterDao {
    	@Autowired
    	private SessionFactory sessionFactory;
    	
    
    		@SuppressWarnings("unchecked")
    
    	public List<Title> listTitle() {
    		return (List<Title>) sessionFactory.getCurrentSession().createQuery("from Title").list();
    	}
    }
    Last edited by nayal_java; 11-19-2013 at 11:07 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Hibernate Spring Struts Integration Problem

    You either autowire or you use the xml configuration.
    The simplest would probably be to remove the autowire and add a valid setter to the class.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    nayal_java is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default Re: Hibernate Spring Struts Integration Problem

    Thanks toll ,my problem is solved

    Either we use autowire in DaoImpl,then we dont have to give sessionfactory reference to DaoImpl bean in XML configuration as follows:

    <bean id="masterDao" class="dao.MasterDaoImpl">
    <property name="sessionFactory" ref="sessionFactory" /> //we need this line only if we are using getter/setter of session factory in DaoImpl class
    </bean>

Similar Threads

  1. Replies: 19
    Last Post: 11-18-2013, 01:09 PM
  2. Replies: 1
    Last Post: 02-01-2013, 11:23 AM
  3. Java, Spring, Struts, Hibernate, Abnitio, Oracle, Teradata
    By rajesh2345 in forum Reviews / Advertising
    Replies: 1
    Last Post: 01-14-2013, 10:31 AM
  4. Want to learn Struts,Hibernate and spring
    By pavanrai in forum Struts
    Replies: 4
    Last Post: 02-01-2012, 12:23 PM
  5. Replies: 0
    Last Post: 08-20-2009, 08:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •