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

  • #16
    hi,

    no i dont have this variable

    the class ServiceImpl :
    Code:
    package istia.st.springmvc.personnes.service;
    
    import istia.st.springmvc.personnes.entites.Personne;
    import istia.st.springmvc.personnes.hibernate.Personnes;
    import istia.st.springmvc.personnes.dao.IDao;
    
    import java.util.Collection;
    import java.util.List;
    
    
    public class ServiceImpl implements IService {
    
    	// la couche [dao]
    	private IDao dao;
    
    	public IDao getDao() {
    		return dao;
    	}
    
    	public void setDao(IDao dao) {
    		this.dao = dao;
    	}
    
    	// liste des personnes
    	public List getAll() {
    		return dao.getAll();
    	}
    
    	// obtenir une personne en particulier
    	public Personnes getOne(int id) {
    		return dao.getOne(id);
    	}
    
    	// ajouter ou modifier une personne
    	public void saveOne(Personnes personne) {
    		dao.saveOne(personne);
    	}
    
    	// suppression d'une personne
    	public void deleteOne(int id) {
    		dao.deleteOne(id);
    	}
    
    	// sauvegarder une collection de personnes
    	public void saveMany(Personnes[] personnes) {
    		// on boucle sur le tableau des personnes
    		for (int i = 0; i < personnes.length; i++) {
    			dao.saveOne(personnes[i]);
    		}
    	}
    
    	// supprimer une collection de personnes
    	public void deleteMany(int[] ids) {
    		// ids : les id des personnes à supprimer
    		for (int i = 0; i < ids.length; i++) {
    			dao.deleteOne(ids[i]);
    		}
    	}
    }
    and the interface :
    Code:
    package istia.st.springmvc.personnes.service;
    
    import istia.st.springmvc.personnes.entites.Personne;
    import istia.st.springmvc.personnes.hibernate.Personnes;
    
    import java.util.Collection;
    import java.util.List;
    
    public interface IService {
    	// 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);
    
    	// ajouter plusieurs personnes
    	void saveMany(Personnes[] personnes);
    
    	// supprimer plusieurs personnes
    	void deleteMany(int ids[]);
    }
    thank you very much

    Comment


    • #17
      and the class personne who are generated automaticlly by middelgen is :
      Code:
      package istia.st.springmvc.personnes.hibernate;
      
      import java.io.Serializable;
      import java.util.Date;
      import org.apache.commons.lang.builder.ToStringBuilder;
      
      
      /** @author Hibernate CodeGenerator */
      public class Personnes implements Serializable {
      
          /** identifier field */
          private Integer Id;
      
          /** nullable persistent field */
          private Integer Version;
      
          /** nullable persistent field */
          private Date Datenaissance;
      
          /** nullable persistent field */
          private String Nom;
      
          /** nullable persistent field */
          private String Prenom;
      
          /** nullable persistent field */
          private Integer Nbenfants;
      
          /** nullable persistent field */
          private Integer Marie;
      
          /** full constructor */
          public Personnes(Integer Version, Date Datenaissance, String Nom, String Prenom, Integer Nbenfants, Integer Marie) {
              this.Version = Version;
              this.Datenaissance = Datenaissance;
              this.Nom = Nom;
              this.Prenom = Prenom;
              this.Nbenfants = Nbenfants;
              this.Marie = Marie;
          }
      
          /** default constructor */
          public Personnes() {
          }
      
          public Integer getId() {
              return this.Id;
          }
      
          public void setId(Integer Id) {
              this.Id = Id;
          }
      
          public Integer getVersion() {
              return this.Version;
          }
      
          public void setVersion(Integer Version) {
              this.Version = Version;
          }
      
          public Date getDatenaissance() {
              return this.Datenaissance;
          }
      
          public void setDatenaissance(Date Datenaissance) {
              this.Datenaissance = Datenaissance;
          }
      
          public String getNom() {
              return this.Nom;
          }
      
          public void setNom(String Nom) {
              this.Nom = Nom;
          }
      
          public String getPrenom() {
              return this.Prenom;
          }
      
          public void setPrenom(String Prenom) {
              this.Prenom = Prenom;
          }
      
          public Integer getNbenfants() {
              return this.Nbenfants;
          }
      
          public void setNbenfants(Integer Nbenfants) {
              this.Nbenfants = Nbenfants;
          }
      
          public Integer getMarie() {
              return this.Marie;
          }
      
          public void setMarie(Integer Marie) {
              this.Marie = Marie;
          }
      
          public String toString() {
              return new ToStringBuilder(this)
                  .append("Id", getId())
                  .toString();
          }
      
      }

      Comment


      • #18
        mdeinum:
        thanks for the reply
        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.
        wondered about this, my question now would be (sorry for my ignorance)

        That way you prevent users from grabbing that bean and bypass the proxied instance.
        how they can do that?

        Esil2008:
        Code:
        // la couche [dao]
        private IDao dao;
        now you see the variable

        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="dao">
          	<ref local="myPersonneDao" /> 
          	</property>
          	</bean>
        see that myPersonneDao is an implementation of the interface, so here there is no problem

        regards

        Comment


        • #19
          thank you very much, I know that it overindulge but I have another probelem
          now i have an exception
          Code:
          Etat HTTP 500 -
          
          type Rapport d'exception
          
          message
          
          description Le serveur a rencontré une erreur interne () qui l'a empêché de satisfaire la requête.
          
          exception
          
          javax.servlet.ServletException: "Servlet.init()" pour la servlet personnes a généré une exception
          	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
          	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
          	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
          	org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
          	org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
          	org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
          	org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
          	java.lang.Thread.run(Unknown Source)
          
          cause mère
          
          org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Personnes.ListController' defined in ServletContext resource [/WEB-INF/personnes-servlet.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 [istia.st.springmvc.personnes.web.ListPersonnes] to required type [istia.st.springmvc.personnes.service.IService] for property 'service']
          	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1066)
          	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
          	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
          	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
          	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
          	org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:537)
          	org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:186)
          	org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.initApplicationContext(SimpleUrlHandlerMapping.java:96)
          	org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
          	org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:84)
          	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:277)
          	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:395)
          	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
          	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
          	org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:283)
          	org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:313)
          	org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:139)
          	org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:306)
          	org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:251)
          	org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:220)
          	org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:112)
          	javax.servlet.GenericServlet.init(GenericServlet.java:212)
          	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
          	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
          	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
          	org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
          	org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
          	org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
          	org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
          	java.lang.Thread.run(Unknown Source)
          
          cause mère
          
          PropertyAccessExceptionsException (1 errors)
          	org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:781)
          	org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:753)
          	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1057)
          	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:857)
          	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:378)
          	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
          	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
          	org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:537)
          	org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:186)
          	org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.initApplicationContext(SimpleUrlHandlerMapping.java:96)
          	org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
          	org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:84)
          	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:277)
          	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:395)
          	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
          	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
          	org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:283)
          	org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:313)
          	org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:139)
          	org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:306)
          	org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:251)
          	org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:220)
          	org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:112)
          	javax.servlet.GenericServlet.init(GenericServlet.java:212)
          	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
          	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
          	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
          	org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
          	org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
          	org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
          	org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
          	java.lang.Thread.run(Unknown Source)
          
          note La trace complète de la cause mère de cette erreur est disponible dans les fichiers journaux de Apache Tomcat/5.5.23.

          Comment


          • #20
            the file personnes-servlet.xml who manage the servlet is :
            Code:
            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
            <beans>
            	<!-- les mappings de l'application-->
            	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            		<property name="mappings">
            			<props>
            				<prop key="/list.html">Personnes.ListController</prop>
            				<prop key="/delete.html">Personnes.DeleteController</prop>
            				<prop key="/edit.html">Personnes.EditController</prop>
            			</props>
            		</property>
            	</bean>
            	
            	<bean name="openSessionInViewInterceptor"  
                class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
                   <property name="sessionFactory"><ref bean="sessionFactory"/></property>
              	</bean>
              
            	<!-- LES CONTROLEURS -->
            	<bean id="Personnes.ListController" 
            		class="istia.st.springmvc.personnes.web.ListPersonnes">
            		<property name="service">
            			<ref bean="Personnes.ListController"/>
            		</property>
            	</bean>
            	<bean id="Personnes.DeleteController" 
            		class="istia.st.springmvc.personnes.web.DeletePersonne">
            		<property name="service">
            			<ref bean="Personnes.DeleteController"/>
            		</property>
            	</bean>
            	<bean id="Personnes.EditController" 
            		class="istia.st.springmvc.personnes.web.EditPersonne">
            		<property name="sessionForm">
            			<value>true</value>
            		</property>
            		<property name="commandName">
            			<value>personne</value>
            		</property>
            		<property name="validator">
            			<ref bean="Personnes.Validator"/>
            		</property>
            		<property name="formView">
            			<value>edit</value>
            		</property>
            		<property name="service">
            			<ref bean="Personnes.EditController"/>
            		</property>
            	</bean>
            	<!-- le validateur -->
            	<bean id="Personnes.Validator" 
            		class="istia.st.springmvc.personnes.web.ValidatePersonne"/>
            	<!-- le résolveur de vues -->
            	<bean class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
            		<property name="basename">
            			<value>vues</value>
            		</property>
            	</bean>
            	<!-- le gestionnaire d'exceptions -->
            	<bean
            		class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
            		<property name="exceptionAttribute">
            			<value>exception</value>
            		</property>
            		<property name="defaultStatusCode">
            			<value>200</value>
            		</property>
            		<property name="defaultErrorView">
            			<value>exception</value>
            		</property>
            	</bean>
            	<!-- le fichier des messages -->
            	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
            		<property name="basename">
            			<value>messages</value>
            		</property>
            	</bean>
            </beans>
            and for example the code of EditPersonne is
            Code:
            package istia.st.springmvc.personnes.web;
            
            import java.text.SimpleDateFormat;
            import istia.st.springmvc.personnes.dao.DaoException;
            import istia.st.springmvc.personnes.entites.Personne;
            import istia.st.springmvc.personnes.hibernate.Personnes;
            import istia.st.springmvc.personnes.service.IService;
            
            import javax.servlet.http.HttpServletRequest;
            import javax.servlet.http.HttpServletResponse;
            
            import org.springframework.beans.propertyeditors.CustomDateEditor;
            import org.springframework.validation.BindException;
            import org.springframework.web.bind.RequestUtils;
            import org.springframework.web.bind.ServletRequestDataBinder;
            import org.springframework.web.servlet.ModelAndView;
            import org.springframework.web.servlet.mvc.SimpleFormController;
            
            public class EditPersonne extends SimpleFormController {
            	// service
            	IService service;
            
            	public IService getService() {
            		return service;
            	}
            
            	public void setService(IService service) {
            		this.service = service;
            	}
            
            	// enregistrement d'éditeurs de propriétés
            	protected void initBinder(HttpServletRequest request,
            			ServletRequestDataBinder binder) throws Exception {
            		// format attendu pour la date de naissance
            		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
            		// format strict
            		dateFormat.setLenient(false);
            		// on enregistre un éditeur de propriétés String (dd/MM/yyyy) -> Date
            		// CustomDateEditor est fourni par Spring - il sera utilisé par Spring
            		// pour transformer
            		// la chaîne saisie dans le formulaire en type java.util.Date
            		// la date ne pourra être vide (2ième paramètre de CustomDateEditor)
            		binder.registerCustomEditor(java.util.Date.class, null,
            				new CustomDateEditor(dateFormat, false));
            	}
            
            	// préparation [Personne] à afficher
            	protected Object formBackingObject(HttpServletRequest request) {
            		// on récupère l'id de la personne
            		int id = RequestUtils.getIntParameter(request, "id", -1);
            		// ajout ou modification ?
            		Personnes personne = null;
            		if (id != -1) {
            			// modification - on récupère la personne à modifier
            			personne = service.getOne(id);
            		}else{
            			// ajout - on crée une personne vide
            			personne = new Personnes();
            			personne.setId(-1);
            		}
            		// on rend l'objet [Personne]
            		return personne;
            	}
            
            	// exécution de la commande
            	protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
            		// sauvegarde la personne ajoutée ou modifiée
            		Personnes personne = (Personnes) command;
            		int idPersonne = personne.getId();
            		try {
            			// sauvegarde de la personne
            			service.saveOne(personne);
            			// on redirige vers la liste des personnes
            			return new ModelAndView("r-list");
            		} catch (DaoException ex) {
            			// on note l'erreur
            			String message=idPersonne==-1 ? "personne.ajout.echec" : "personne.modification.echec";
            			errors.reject(message,new Object[]{ex.getMessage()},"Echec de la mise à jour: {0}");
            			// on réaffiche le formulaire
            			return showForm(request,response, errors);
            		}
            	}
            
            }

            Comment


            • #21
              also if it help the code of ListPersonnes is
              Code:
              package istia.st.springmvc.personnes.web;
              
              import java.util.HashMap;
              import java.util.Map;
              
              import istia.st.springmvc.personnes.service.IService;
              
              import javax.servlet.http.HttpServletRequest;
              import javax.servlet.http.HttpServletResponse;
              
              import org.springframework.web.servlet.ModelAndView;
              import org.springframework.web.servlet.mvc.Controller;
              
              public class ListPersonnes implements Controller {
              
              	// service
              	IService service;
              
              	public IService getService() {
              		return service;
              	}
              
              	public void setService(IService service) {
              		this.service = service;
              	}
              
              	// gestion de la requête
              	public ModelAndView handleRequest(HttpServletRequest request,
              			HttpServletResponse response) throws Exception {
              		// le modèle de la vue[list]
              		Map model = new HashMap();
              		model.put("personnes", service.getAll());
              		// résultat
              		return new ModelAndView("list", model);
              	}
              
              }

              Comment


              • #22
                I would presume the type you are trying to inject doesn't implement the correct interface.
                Last edited by karldmoore; Aug 29th, 2007, 12:58 PM.

                Comment

                Working...
                X