Announcement Announcement Module
Collapse
No announcement yet.
Hibernate/Spring SessionFactory Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate/Spring SessionFactory

    Hi all,
    I'm trying to integrate hibernate and spring into a test project. This is my first foray into Spring and Hibernate.
    When I start Tomcat (5.5) I get the following error:

    Code:
    ERROR [http-8081-Processor23] - Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myPersonneDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0] to required type [net.sf.hibernate.SessionFactory] for property 'sessionFactory']
    PropertyAccessExceptionsException (1 errors)
    org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0] to required type [net.sf.hibernate.SessionFactory] for property 'sessionFactory'
    	at org.springframework.beans.BeanWrapperImpl.doTypeConversionIfNecessary(BeanWrapperImpl.java:951)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:692)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:572)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:737)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:764)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:753)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1057)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:283)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:313)
    	at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:139)
    	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764)
    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216)
    	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
    	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
    	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
    	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
    	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:519)
    	at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1220)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.apache.commons.modeler.BaseModelMBean.invoke(BaseModelMBean.java:457)
    	at com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(Unknown Source)
    	at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(Unknown Source)
    	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
    	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
    	at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1397)
    	at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:815)
    	at org.apache.catalina.manager.HTMLManagerServlet.deployInternal(HTMLManagerServlet.java:249)
    	at org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:96)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
    	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
    	at java.lang.Thread.run(Unknown Source)
     INFO [http-8081-Processor23] - Closing Spring root WebApplicationContext
    Here's the applicationContext.xml:

    Code:
    <!DOCTYPE beans PUBLIC 	"-//SPRING//DTD BEAN//EN" 
    	"http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>	
    
    	<bean id="dataSource" 
    		  class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
    		<property name="driverClassName">
    			<value>com.mysql.jdbc.Driver</value>
    		</property>
    		<property name="url">
    			<value>jdbc:mysql://localhost/dbpersonnes</value>
    		</property>
    		<property name="username"><value>root</value></property>
    		<property name="password"><value></value></property>
    	</bean>
    
    	<bean id="sessionFactory"
    		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource">
    			<ref local="dataSource"/>
    		</property>
    		<property name="mappingResources">
    		<list>
    			<value>Personnes.hbm.xml</value>
    		</list>
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">
    					org.hibernate.dialect.MySQLDialect
    				</prop>
    				<prop key="hbm2java">update</prop>
    			</props>
    		</property>
    	</bean>
    	
    	<bean id="myTransactionManager"
            class="org.springframework.orm.hibernate3.HibernateTransactionManager">
           <property name="sessionFactory">
       		<ref local="sessionFactory"/>
    		</property>
        </bean>
        
        <bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
             <property name="sessionFactory">
               <ref bean="sessionFactory"/>
             </property>
        </bean>    
      	
      	<bean id="myPersonneDao" class="istia.st.springmvc.personnes.dao.DaoImplCommon">
    		<property name="sessionFactory"><ref local="sessionFactory"/></property>
    	</bean>
    	<bean id="personneManager" >
    		<property name="sessionFactory">
    		<bean class="istia.st.springmvc.personnes.service.ServiceImpl">
    		<property name="myPersonneDao" ref="myPersonneDao"/>
    		</bean>
    		</property>
    	</bean>
    
    </beans>
    I think I may have a problem mixing Hibernate 2 and 3 jars since I think the package name of net.sf.hibernate.SessionFactory may be from Hibernate v2 to v3 but I'm not sure.

    I'd appreciate any help.
    Thanks!

  • #2
    Hello
    org.springframework.beans.factory.BeanCreationExce ption:
    Error creating bean with name 'myPersonneDao' defined in ServletContext
    resource [/WEB-INF/applicationContext.xml]:
    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 [$Proxy0] to required type [net.sf.hibernate.SessionFactory] for property 'sessionFactory']
    tell me your
    Code:
    <bean id="myPersonneDao" class="istia.st.springmvc.personnes.dao.DaoImplCommon">
    	<property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>
    myPersonneDao is class that implements an interface right?
    and it extends HibernateDaoSupport from the package
    import org.springframework.orm.hibernate3.support.Hiberna teDaoSupport; ??

    if you can share code of the DAO class it would help us

    I think I may have a problem mixing Hibernate 2 and 3 jars since I think the package name of net.sf.hibernate.SessionFactory may be from Hibernate v2 to v3 but I'm not sure.
    i saw in you configuration that you use
    orm.hibernate3

    HTH

    regards

    Comment


    • #3
      thanks for your response,

      the code of DAO class is bellow

      Code:
      package istia.st.springmvc.personnes.dao;
      
      import istia.st.springmvc.personnes.entites.Personne;
      import istia.st.springmvc.personnes.hibernate.HibernateUtil;
      import istia.st.springmvc.personnes.hibernate.Personnes;
      import istia.st.springmvc.personnes.utils.SpringUtils;
      
      import org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException;
      
      import org.hibernate.HibernateException;
      import org.hibernate.Session;
      import org.hibernate.SessionFactory;
      import org.hibernate.cfg.Configuration;
      
      import org.springframework.orm.hibernate.support.HibernateDaoSupport;
      import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
      
      import java.util.Collection;
      import java.util.Iterator;
      import java.util.List;
      
      
      public class DaoImplCommon extends HibernateDaoSupport implements
      		IDao {
      	    // configuration: parametres + mapping
      	    public Configuration config = null;
      	
      	    // Usine à fabriquer des sessions
      	    public SessionFactory factory = null;
      	    
      	// liste des personnes
      	public List getAll() {  
      		
              return getHibernateTemplate().find(
              		"from Personnes ");
      	}
      
      	// obtenir une personne en particulier
      	public Personnes getOne(int id) {
      		
      		// on la récupère dans la BD
      		
      		try
      		{
      		    if ((Integer)id != null)
      		    {
      			List r = getHibernateTemplate().find(
      				"from Personnes where id = "+id);
      			if (r.size() == 0)
      			{
      			    return null;
      			}
      			else
      			{
      			    return (Personnes) r.get(0);
      			}
      		    }
      
      		    return null;
      		}
      		catch (HibernateObjectRetrievalFailureException e)
      		{
      		    return null;
      		}
      	}
      
      	// suppression d'une personne
      	public void deleteOne(int id) {
      		// on supprime la personne
      		/*int n = getSqlMapClientTemplate().delete("Personne.deleteOne",
      				new Integer(id));
      		// a-t-on réussi
      		if (n == 0) {
      			throw new DaoException("Personne d'id [" + id + "] inconnue", 2);
      		}*/
      	}
      
      	// ajouter ou modifier une personne
      	public void saveOne(Personnes personne) {
      		// le paramètre personne est-il valide ?
      		check(personne);
      		// ajout ou modification ?
      		if (personne.getId() == -1) {
      			// ajout
      			insertPersonne(personne);
      		} else {
      			updatePersonne(personne);
      		}
      	}
      
      	// ajouter une personne
      	protected void insertPersonne(Personnes personne) {
      		// 1ère version
      		personne.setVersion(1);
      		getHibernateTemplate().save(personne);
      	}
      
      	// modifier une personne
      	protected void updatePersonne(Personnes personne) {
      		// on attend 10 ms - pour les tests mettre true au lieu de false
      		//getHibernateTemplate().update(personne);
      	}
      
      	// vérification validité d'une personne
      	private void check(Personnes p) {
      		// personne p
      		if (p == null) {
      			throw new DaoException("Personne null", 10);
      		}
      		// id
      		if (p.getId() != -1 && p.getId() < 0) {
      			throw new DaoException("Id [" + p.getId() + "] invalide", 11);
      		}
      		// date de naissance
      		if (p.getDatenaissance() == null) {
      			throw new DaoException("Date de naissance manquante", 12);
      		}
      		// nombre d'enfants
      		if (p.getNbenfants() < 0) {
      			throw new DaoException("Nombre d'enfants [" + p.getNbenfants()
      					+ "] invalide", 13);
      		}
      		// nom
      		if (p.getNom() == null || p.getNom().trim().length() == 0) {
      			throw new DaoException("Nom manquant", 14);
      		}
      		// prénom
      		if (p.getPrenom() == null || p.getPrenom().trim().length() == 0) {
      			throw new DaoException("Prénom manquant", 15);
      		}
      	}
      
      	// attente
      	private void wait(int N) {
      		// on attend N ms
      		try {
      			Thread.sleep(N);
      		} catch (InterruptedException e) {
      			// on affiche la trace de l'exception
      			e.printStackTrace();
      			return;
      		}
      	}
      
      }
      and the IDAO interface is
      Code:
      package istia.st.springmvc.personnes.dao;
      
      import istia.st.springmvc.personnes.entites.Personne;
      import istia.st.springmvc.personnes.hibernate.Personnes;
      
      import java.util.Collection;
      import java.util.List;
      
      public interface IDao {
      	// liste de toutes les personnes
      	List getAll();
      	// obtenir une personne particulière
      	Personnes getOne(int id);
      	// ajouter/modifier une personne
      	void saveOne(Personnes personne);
      	// supprimer une personne
      	void deleteOne(int id);
      }
      I checked everywhere if there is a use of packages starting by net.sf (hibernate2), the only place where they are it is in the files of configurantion of middlegen, that I used to generate the mapping files
      the code of this file

      Code:
      <?xml version="1.0" encoding="utf-8"?>
      
      <!--
        This build file is generated by MiddlegenIDE.
        
        MiddlegenIDE: http://ultimania.org/middlegenide/
      -->
      
      <project name="Middlegen Hibernate" default="compile" basedir="../.">
         <property file=".././build.properties"/>
         <property name="hibernate.cascade"    value="all" />
         <property name="package"              value="org.ultimania.model" />
         <property name="gen.xdoclet-tag"      value="false" />
         <property name="gui"                  value="true" />
         <property name="jdbc.jar"             value="C:\Documents and Settings\jamal\Mes documents\Appli\springmvc4-code\mvc-37\lib\mysql-connector-java-3.1.9-bin.jar" />
         <property name="database.driver"      value="com.mysql.jdbc.Driver" />
         <property name="lib.dir"              value="/C:/Documents and Settings/jamal/Mes documents/LOGICIELS/wtp-all-in-one-sdk-R-1.5.0-200606281455-win32/eclipse/plugins/net.sf.middlegen_2.1.91/lib/" />
         <property name="database.url"         value="jdbc:mysql://localhost/dbpersonnes" />
         <property name="database.userid"      value="root" />
         <property name="database.password"    value="" />
         <property name="database.schema"      value="" />
         <property name="database.catalog"     value="" />
         <property name="dest.dir"             value="WEB-INF/src" />
      
         <target name="init" depends="prepare,fail-if-no-middlegen,fail-if-no-hibernate,fail-if-no-hibernate-ext">
      
           <taskdef
              name="middlegen"
              classname="middlegen.MiddlegenTask"
              classpathref="middlegen.classpath"
           />
      
           <taskdef
              name="hbm2java"
              classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
              classpathref="hibernate-ext.classpath"
           />
      
          <mkdir dir="${dest.dir}"/>
         
         </target>
      
         <target name="prepare">
      
           <path id="middlegen.classpath">
              <pathelement path="${jdbc.jar}"/>
              <fileset dir="${lib.dir}" includes="*.jar"/>
           </path>
      
           <path id="hibernate-ext.classpath">
             <fileset dir="${lib.dir}"           includes="*.jar"/>
           </path>
      
           <available property="middlegen" classname="middlegen.MiddlegenTask" classpathref="middlegen.classpath"/>
           <available property="hibernate" classname="net.sf.hibernate.Hibernate" classpathref="hibernate-ext.classpath"/>
           <available property="hibernate-ext" classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask" classpathref="hibernate-ext.classpath"/>
      
      
         </target>
      
         <target name="fail-if-no-middlegen" unless="middlegen">
            <fail>
            Middlegen is not found. Please install Middlegen.
            </fail>
         </target>
      
         <target name="fail-if-no-hibernate" unless="hibernate">
            <fail>
            Hibernate is not found. Please install Hibernate.
            </fail>
         </target>
      
         <target name="fail-if-no-hibernate-ext" unless="hibernate-ext">
            <fail>
            Hibernate-Extension is not found. Please install Hibernate-Extenstion.
            </fail>
         </target>
          
         <target name="gen-hbm" depends="init">
      
          <middlegen
               appname="org.ultimania.model"
               prefsdir="."
               gui="${gui}"
               databaseurl="${database.url}"
               driver="${database.driver}"
               username="${database.userid}"
               password="${database.password}"
               schema="${database.schema}"
               catalog="${database.catalog}"
            >
               <hibernate
               	version="3.0"
                  destination="${dest.dir}"
                  package="${package}"
                  genXDocletTags="${gen.xdoclet-tag}"
             	    standardCascade="${hibernate.cascade}"
      	    javaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper"
      	 />
      	 <table name="personnes" />
          </middlegen>
        </target>
      
        <target name="gen-java" depends="gen-hbm">
          <hbm2java output="${dest.dir}">
            <fileset dir="${dest.dir}">
              <include name="**/*.hbm.xml" />
            </fileset>
          </hbm2java>
        </target>
      
        <target name="compile" depends="gen-java">
        </target>
      
      </project>
      thanks

      Comment


      • #4
        hello

        see part of my code
        Code:
        
        import org.springframework.dao.DataAccessException;
        import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
        import org.springframework.orm.hibernate3.HibernateCallback;
        
        /**
         * Clase DAO que trabaja con Hibernate y manipula Directamente Objetos Proveedor
         * @author Manuel Jordan 
         * @since Marzo 2007 
         */
        public class ProveedorDAOImpl extends HibernateDaoSupport implements ProveedorDAOService{
        
        	/**
        	 * <p>Metodo Que retorna todos los proveedores existendes en la DB</p>
        	 * <p>LLamado por su correspondiente getAllProveedoresBO en ConcreteProveedorImpl</p>
        	 * 
        	 * @param 
        	 * @return todos los proveedores 
        	 * @exception MyListEmptyException en caso de que no exista en la db ningun proveedor 
        	 * @throws MyGlobalException en caso de falla externa lo lanzo globalmente
        	 * @see ConcreteProveedorImpl
        	 * 
        	 */
        	public List<Proveedor> getAllProveedoresDAO()throws MyGlobalException{
        		List<Proveedor> mylist = new ArrayList<Proveedor>();
        		try{
        			mylist = (List) getHibernateTemplate().find("FROM Proveedor p WHERE p.idProveedor!='100000' ");			
        			if(mylist.isEmpty())
        				throw new MyListEmptyException();
        		}
        		catch(DataAccessException dae){
        			logger.info("DataAccessException"+dae.getMessage());
        			throw new MyGlobalException();
        		}	
        		return mylist;
        	}
        in you code i see this
        Code:
        import org.springframework.orm.hibernate.support.HibernateDaoSupport;
        and the mime is
        Code:
        import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
        yes the difference is the number 3

        try this and let me know you progress

        regards

        Comment


        • #5
          ok i will try

          Comment


          • #6
            now i have an other error message, i think the first problem is solve thank you very much

            Code:
            ERROR [http-8081-Processor25] - Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
            org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personneManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.IllegalStateException: Bean definition does not carry a resolved bean class
            java.lang.IllegalStateException: Bean definition does not carry a resolved bean class
            	at org.springframework.beans.factory.support.AbstractBeanDefinition.getBeanClass(AbstractBeanDefinition.java:252)
            	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:52)
            	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:486)
            	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:362)
            	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
            	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
            	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:283)
            	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:313)
            	at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:139)
            	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
            	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
            	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
            	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764)
            	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216)
            	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
            	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
            	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
            	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
            	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:519)
            	at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1220)
            	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            	at java.lang.reflect.Method.invoke(Unknown Source)
            	at org.apache.commons.modeler.BaseModelMBean.invoke(BaseModelMBean.java:457)
            	at com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(Unknown Source)
            	at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(Unknown Source)
            	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
            	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
            	at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1397)
            	at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:815)
            	at org.apache.catalina.manager.HTMLManagerServlet.deployInternal(HTMLManagerServlet.java:249)
            	at org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:96)
            	at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
            	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
            	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
            	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
            	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
            	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
            	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
            	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
            	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
            	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
            	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
            	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
            	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
            	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
            	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
            	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
            	at java.lang.Thread.run(Unknown Source)
             INFO [http-8081-Processor25] - Closing Spring root WebApplicationContext

            Comment


            • #7
              Hello

              Code:
              <bean id="personneManager" >
               <property name="sessionFactory">
              
              	<bean class="istia.st.springmvc.personnes.service.ServiceImpl">
              	   <property name="myPersonneDao" ref="myPersonneDao"/>
              	</bean>
              
                </property>
              </bean>
              first time that i see a bean defined in other bean

              BTW a personneManager like any BO shouldnt has a reference to a sessionFactory, it normally belong to the DAO objects

              HTH

              regards

              Comment


              • #8
                hello
                so i can't define a bean in an other bean , ok thanks
                the problem it is that I begin with that; this code I took it from many examples in the web. can you explain me more or give me an example.
                in fact i wrote this to make a connection between the service layer and DAO layer

                Comment


                • #9
                  You can define a bean inside another bean, sometimes this is even prefered instead of defining 2 separate beans.

                  However you are injecting ServiceImpl into a sessionFactory property, which to me are 2 incompatible types. Also your personneManager bean doesn't have a class, that way it is quite hard to determine what to instantiate...

                  Code:
                  <bean id="personneManager" class="?">
                   <property name="sessionFactory">
                  
                  	<bean class="istia.st.springmvc.personnes.service.ServiceImpl">
                  	   <property name="myPersonneDao" ref="myPersonneDao"/>
                  	</bean>
                  
                    </property>
                  </bean>

                  Comment


                  • #10
                    hi,
                    this code are correct ?
                    Code:
                    <bean id="service" class="istia.st.springmvc.personnes.service.ServiceImpl" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
                    	<property name="myPersonneDao">
                      	<ref local="myPersonneDao" /> 
                      	</property>
                      	</bean>
                    can this code make a connection between the service layer and DAO layer

                    thanks

                    Comment


                    • #11
                      hi mdeinum,
                      you are right, I think that I have done an inopportune copy past.
                      thanks

                      Comment


                      • #12
                        mdeinum:
                        You can define a bean inside another bean, sometimes this is even prefered instead of defining 2 separate beans.
                        can you tell me in which cases???

                        Esil2008:
                        is this resolved?

                        regards

                        Comment


                        • #13
                          no, i have an other error

                          Code:
                          ERROR [http-8081-Processor25] - Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
                          org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'service' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'myPersonneDao' of bean class [istia.st.springmvc.personnes.service.ServiceImpl]: Bean property 'myPersonneDao' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
                          org.springframework.beans.NotWritablePropertyException: Invalid property 'myPersonneDao' of bean class [istia.st.springmvc.personnes.service.ServiceImpl]: Bean property 'myPersonneDao' 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.setPropertyValue(BeanWrapperImpl.java:670)
                          	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:572)
                          	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:737)
                          	at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:764)
                          	at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:753)
                          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1057)
                          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
                          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
                          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
                          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
                          	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:283)
                          	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:313)
                          	at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:139)
                          	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
                          	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
                          	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
                          	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764)
                          	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216)
                          	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
                          	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
                          	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
                          	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
                          	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:519)
                          	at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1220)
                          	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                          	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                          	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                          	at java.lang.reflect.Method.invoke(Unknown Source)
                          	at org.apache.commons.modeler.BaseModelMBean.invoke(BaseModelMBean.java:457)
                          	at com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(Unknown Source)
                          	at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(Unknown Source)
                          	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
                          	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
                          	at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1397)
                          	at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:815)
                          	at org.apache.catalina.manager.HTMLManagerServlet.deployInternal(HTMLManagerServlet.java:249)
                          	at org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:96)
                          	at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
                          	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                          	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
                          	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
                          	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
                          	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
                          	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
                          	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                          	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
                          	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
                          	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
                          	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
                          	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
                          	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
                          	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
                          	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
                          	at java.lang.Thread.run(Unknown Source)
                           INFO [http-8081-Processor25] - Closing Spring root WebApplicationContext
                          my applicationContext.xml now is :

                          Code:
                          <!DOCTYPE beans PUBLIC 	"-//SPRING//DTD BEAN//EN" 
                          	"http://www.springframework.org/dtd/spring-beans.dtd">
                          
                          <beans>	
                          
                          	<bean id="dataSource" 
                          		  class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
                          		<property name="driverClassName">
                          			<value>com.mysql.jdbc.Driver</value>
                          		</property>
                          		<property name="url">
                          			<value>jdbc:mysql://localhost/dbpersonnes</value>
                          		</property>
                          		<property name="username"><value>root</value></property>
                          		<property name="password"><value></value></property>
                          	</bean>
                          
                          	<bean id="sessionFactory"
                          		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                          		<property name="dataSource">
                          			<ref local="dataSource"/>
                          		</property>
                          		<property name="mappingResources">
                          		<list>
                          			<value>Personnes.hbm.xml</value>
                          		</list>
                          		</property>
                          		<property name="hibernateProperties">
                          			<props>
                          				<prop key="hibernate.dialect">
                          					org.hibernate.dialect.MySQLDialect
                          				</prop>
                          				<prop key="hbm2java">update</prop>
                          			</props>
                          		</property>
                          	</bean>
                          	
                          	<bean id="myTransactionManager"
                                  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
                                 <property name="sessionFactory">
                             		<ref local="sessionFactory"/>
                          		</property>
                              </bean>
                              
                              <bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
                                   <property name="sessionFactory">
                                     <ref bean="sessionFactory"/>
                                   </property>
                              </bean>    
                            	
                            	<bean id="myPersonneDao" class="istia.st.springmvc.personnes.dao.DaoImplCommon">
                          		<property name="sessionFactory"><ref local="sessionFactory"/></property>
                          	</bean>
                          	
                          	<bean id="service" class="istia.st.springmvc.personnes.service.ServiceImpl" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
                          	<property name="myPersonneDao">
                            	<ref local="myPersonneDao" /> 
                            	</property>
                            	</bean>
                            	
                          </beans>

                          Comment


                          • #14
                            ok

                            in you class ServiceImpl

                            is there the variable myPersonneDao and its set property?

                            pls shown your code

                            regards

                            Comment


                            • #15
                              can you tell me in which cases???
                              Sure.

                              If you are defining ProxyFactoryBeans for instance, it is prefered to specify the target as an anonymous inner class. That way you prevent users from grabbing that bean and bypass the proxied instance.

                              Code:
                              org.springframework.beans.NotWritablePropertyException: Invalid property 'myPersonneDao' of bean class [istia.st.springmvc.personnes.service.ServiceImpl]: Bean property 'myPersonneDao' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
                              This errror indicates that you are trying to inject something but don't have a setter for it.

                              Comment

                              Working...
                              X