Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: no persistent classes found for query class

  1. #1
    Join Date
    Jun 2007
    Location
    Marseille - France
    Posts
    78

    Default no persistent classes found for query class

    Hi,
    First excuse me for my english.
    I would like to put in my comboBox a data from my data base, so i used a method who extract this data
    Code:
    public List getAllDroit() {
    		return getHibernateTemplate().find(
    		"select com.pia.agp.mapping.Droit.droitId from com.pia.agp.mapping.Droit ");
    	}
    her is my controller
    Code:
    package com.pia.agp.web;
    
    import java.text.SimpleDateFormat;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
    
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.beans.propertyeditors.CustomDateEditor;
    import org.springframework.validation.BindException;
    import org.springframework.validation.Errors;
    import org.springframework.validation.ObjectError;
    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;
    
    import com.pia.agp.mapping.Intervenant;
    import com.pia.agp.service.IServiceIntervenant;
    
    public class EditIntervenant extends SimpleFormController {
    	// service
    	IServiceIntervenant service;
    
    	public IServiceIntervenant getService() {
    		return service;
    	}
    
    	public void setService(IServiceIntervenant 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) {
    		System.out.println("[EditPersonne] formBakingObject **************************************");
    		// on récupère l'id de l intervenant
    		int id = RequestUtils.getIntParameter(request, "id", -1);
    		// ajout ou modification ?
    		Intervenant intervenant = null;
    		if (id != -1) {
    			// modification - on récupère l intervenant à modifier
    			intervenant = service.getOne(id);
    		}else{
    			// ajout - on crée un intervenant vide
    			intervenant = new Intervenant();
    			intervenant.setIntervenantId(-1);
    		}
    		// on rend l'objet [ intervenants]
    		return intervenant;
    	}
    
    	// exécution de la commande
    	protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
    		// sauvegarde l intervenant ajoutée ou modifiée
    		System.out.println("[EditPersonne] onSubmit **************************************");
    		Intervenant intervenant = (Intervenant) command;
    		int idIntervenant = intervenant.getIntervenantId();
    		try {
    			// sauvegarde de l intervenant
    			service.saveOne(intervenant);
    			// on redirige vers la liste des  intervenants
    			return new ModelAndView("r-list");
    		} catch (Exception ex) {
    			// on note l'erreur
    			String message=idIntervenant==-1 ? "intervenant.ajout.echec" : "intervenant.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);
    		}
    	}
    
    	protected Map referenceData(HttpServletRequest request, Object model, Errors errors) throws Exception {
    		Map data = new HashMap();
    		//data.putAll(super.referenceData(request, model, errors));
    		
    		if (errors.hasErrors()) {
    			
    			System.out.println("Errors found.....................");
    				
    			for (Iterator iter = errors.getAllErrors().iterator(); iter.hasNext();){
    				ObjectError error = (ObjectError) iter.next();
    					
    				System.out.println("ERROR: " + error.getDefaultMessage());
    			}
    				
    		}	
    			
    		// les options du combo (les fonctions d'un intervenant)
    		data.put("optionsComboFonction",service.getOptionsComboFonction());
    		
    		//les options du combo (les couts journalier d'un intervenant)
    		data.put("optionsComboCoutExpPia",service.getCoutExpPiaCombo());
    		
    		data.put("optionsComboDroit",service.getDroitCombo());
    		
    		// on rend le dictionnaire
    		return data;
    	}
    	 
    }
    so in referenceData i call getDroitCombo, to obtain the data.
    the code of getDroitCombo is :
    Code:
    public String[] getDroitCombo() {
    		System.out.println("Get droit combo ");
    		int i = 0;
    		/* on appel la methode de la couche DAO qui recupere les donnees de la BD*/
    		List list = dao.getAllDroit();
    		String temp[] = new String[list.size()];
    		System.out.println("SIZE : "+list.size());
    		/* On boucle sur notre list pour remplir le tableau de string */
    		for (Iterator iter = list.iterator(); iter.hasNext();){
    			temp[i++] = (String) iter.next();
    			System.out.println(temp[i-1]);
    		}
    		return temp;
    		
    	}
    the problem: I have this warning in the log file of tomcat and the method return nothing.
    Code:
    Get droit combo 
     WARN [http-8081-Processor25] - no persistent classes found for query class: select com.pia.agp.mapping.Droit.droitId from com.pia.agp.mapping.Droit 
    SIZE : 0

    Thanks for your help

  2. #2
    Join Date
    Mar 2007
    Posts
    515

    Default

    Can you post your config file (the relevant part from Hibernate session factory configuration) ?
    Did you check the entities names to be the same as with the ones in your query ?
    Have you googled a little... there are some results there ?

  3. #3
    Join Date
    Jun 2007
    Location
    Marseille - France
    Posts
    78

    Default

    thanks for your reply,
    my config file 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">Intervenant.ListController</prop>
    				<prop key="/delete.html">Intervenant.DeleteController</prop>
    				<prop key="/edit.html">Intervenant.EditController</prop>
    				<prop key="/acceuil.html">Intervenant.AccueilController</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="Intervenant.ListController" 
    		class="com.pia.agp.web.ListIntervenant">
    		<property name="service">
    			<ref bean="service"/>
    		</property>
    	</bean>
    	<bean id="Intervenant.DeleteController" 
    		class="com.pia.agp.web.DeleteIntervenant">
    		<property name="service">
    			<ref bean="service"/>
    			<!--   <ref bean="Intervenant.DeleteController"/> -->
    		</property>
    	</bean>
    	<bean id="Intervenant.AccueilController" 
    		class="com.pia.agp.web.AcceuilIntervenant">
    		<property name="service">
    			<ref bean="service"/>
    		</property>
    	</bean>
    
    	<bean id="Intervenant.EditController" 
    		class="com.pia.agp.web.EditIntervenant">
    		<property name="sessionForm">
    			<value>true</value>
    		</property>
    		<property name="commandName">
    			<value>intervenant</value>
    		</property>
    		<property name="validator">
    			<ref bean="Intervenant.Validator"/>
    		</property>
    		<property name="formView">
    			<value>edit</value>
    		</property>
    		<property name="service">
    			<ref bean="service"/>
    		</property>
    	</bean>
    	<!-- le validateur -->
    	<bean id="Intervenant.Validator" 
    		class="com.pia.agp.web.ValidateIntervenant"/>
    	<!-- 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>
    i used middelgen to generate the mapping files, so i call those entities.
    for the result of the search in google, i found the warning message, but it's not the same context.

    thanks

  4. #4
    Join Date
    Mar 2007
    Posts
    515

    Default

    Code:
    <property name="sessionFactory"><ref bean="sessionFactory"/></property>
    I don't see the definition of sessionFactory...
    My best guess is either your mapping files are in a different folder than the one you configured the session factory, or are not at all.

  5. #5
    Join Date
    Jun 2007
    Location
    Marseille - France
    Posts
    78

    Default

    excuse me, i gave you the wrong file, it was XXX-servlet.xml file. the definition of sessionfactory it in 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/bd_agp</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>com/pia/agp/mapping/Intervenant.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="myIntervenantDao" class="com.pia.agp.dao.DaoIntervenantImpl">
    		<property name="sessionFactory"><ref local="sessionFactory"/></property>
    	</bean>
    	
    	<bean id="service" class="com.pia.agp.service.ServiceIntervenantImpl" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
    	<property name="dao">
      	<ref local="myIntervenantDao" /> 
      	</property>
      	</bean>
      	
    </beans>

    I forgot to specify that i can recover data from another table "Intervenant", i do the same thing, but i post them directly in list (<table>) (not in a comboBox).
    the code is :
    Code:
    public List getAll() {  
    		System.out.println("[DaoImplCommon] getAll ******************************************** "); 
    	    return getHibernateTemplate().find(
    	    		"from com.pia.agp.mapping.Intervenant ");
    	}
    thanks

  6. #6
    Join Date
    Mar 2007
    Posts
    515

    Default

    You tried adding com.pia.agp.mapping.Droit to session factory configuration ?
    Code:
    <property name="mappingResources">
    		<list>
    			<value>com/pia/agp/mapping/Intervenant.hbm.xml</value>
                            <value>com/pia/agp/mapping/Droit.hbm.xml</value>
    		</list>
    		</property>

  7. #7
    Join Date
    Jun 2007
    Location
    Marseille - France
    Posts
    78

    Default

    yes, this is my hibernate.cfg.xml file
    Code:
    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC 
    	"-//Hibernate/Hibernate Configuration DTD//EN"
    	"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
    
    	<session-factory>
    
    		<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    		<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    		<property name="connection.username">root</property>
    		<property name="connection.password"></property> 
    		<property name="connection.url">jdbc:mysql://localhost/bd_agp</property>
            <property name="show_sql">true</property>
            
    		<mapping resource="com/pia/agp/mapping/Achat.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Action.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Compteimputation.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Compterenduactivite.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Coutjournalierexperian.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Cratache.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Depense.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Droit.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Facture.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Frai.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Intervcig.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Intervenant.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Notedefrai.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Organisme.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Postefacture.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Projet.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Tache.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Tacheaction.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Tachecommerciale.hbm.xml" />
    		<mapping resource="com/pia/agp/mapping/Tachetechnique.hbm.xml" />
    
    	</session-factory>
    </hibernate-configuration>
    it is automaticlly generated by middelgen.

    thansks

  8. #8
    Join Date
    Mar 2007
    Posts
    515

    Default

    And how do you associate your hibernate.cfg.xml with the session factory ?
    Shouldn't be specified as configLocation property ?

  9. #9
    Join Date
    Jun 2007
    Location
    Marseille - France
    Posts
    78

    Default

    I dont know how, i think it's automaticlly associated by spring.it is only 3 weeks that I started to work with spring and hibernate, so i didn't understand well the link between the two frameworks

  10. #10
    Join Date
    Mar 2007
    Posts
    515

    Default

    Basically you can configure hibernate session factory using more options. Read the API for LocalSessionFactoryBean.

    If you want to use the hibernate.cfg.xml file, remove <property name="mappingResources" />, <property name="hibernateProperties" /> lines from configuration, and add
    Code:
    <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
    Also, make sure the path to hibernate.cfg.xml is correct.

Posting Permissions

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