IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

Spring 4 Hibernate 5 - maTable is not mapped [Data]


Sujet :

Spring Java

  1. #1
    Membre très actif
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2009
    Messages
    391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2009
    Messages : 391
    Par défaut Spring 4 Hibernate 5 - maTable is not mapped
    Bonjour à tous ,

    j'ai un petit problème lorsque je lance mon projet :

    Exception in thread "main" org.hibernate.hql.internal.ast.QuerySyntaxException: utilisateur is not mapped [from utilisateur]
    at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79)
    at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:218)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142)
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115)
    at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:76)
    at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:150)
    at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:302)
    at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:240)
    at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1907)
    at com.ecollection.dao.UtilisateurDaoImpl.recupererUtilisateurs(UtilisateurDaoImpl.java:37)
    at TestMain.main(TestMain.java:34)
    L'erreur provient de la méthode recupererUtilisateurs() de la classe UtilisateurDaoImpl (la méthode d'insertion fonctionne) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
     
    public class UtilisateurDaoImpl implements UtilisateurDao{
     
    	private SessionFactory sessionFactory;
     
    	public void setSessionFactory(SessionFactory sessionFactory) {
    		this.sessionFactory = sessionFactory;
    	}
     
    	public void creerUtilisateur(Utilisateur adresse) {
    		Session session = sessionFactory.openSession();
    		Transaction transaction = session.beginTransaction();
    		session.save(adresse);
    		transaction.commit();
    		session.close();
    	}
     
    	public List<Utilisateur> recupererUtilisateurs() {
    		Session session = sessionFactory.openSession();
    		List<Utilisateur> res = session.createQuery("from utilisateur").list();
    		session.close();
    		return res;
    	}
     
    }
    Mon entitybean est annoté :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
     
    @Entity
    @Table(name="UTILISATEUR")
    public class Utilisateur {
     
    	public Long id;
     
    	public String nom;
     
    	public Utilisateur() {
    		super();
    	}
     
    	public Utilisateur(String nom) {
    		super();
    		this.nom = nom;
    	}
     
    	@Id
    	@Column(name="id")
    	@GeneratedValue(generator="increment")
    	@GenericGenerator(name="increment",strategy="increment")
    	public Long getId() {
    		return id;
    	}
     
    	public void setId(Long id) {
    		this.id = id;
    	}
     
    	public String getNom() {
    		return nom;
    	}
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    }
    et enfin, je n'ai pas de fichier de configuration hibernate.cfg.xml mais j'ai un fichier de configuration spring.xml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
     
    <?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:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
     
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
    	    destroy-method="close">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
    		<property name="url" value="jdbc:mysql://localhost/ecollection" />
    		<property name="username" value="root" />
    		<property name="password" value="" />
    	</bean>
     
    	<bean id="hibernateAnnotatedSessionFactory" 
    	    class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
     
    		<property name="dataSource" ref="dataSource" />
     
    		<property name="annotatedClasses">
    			<list>
    				<value>com.ecollection.model.Utilisateur</value>
    			</list>
    		</property>
     
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
    				<prop key="hibernate.current_session_context_class">thread</prop>
    				<prop key="hibernate.show_sql">false</prop>
    			</props>
    		</property>
     
    	</bean>
     
    	<bean id="utilisateurDao" class="com.ecollection.dao.UtilisateurDaoImpl">
    		<property name="sessionFactory" ref="hibernateAnnotatedSessionFactory" />
    	</bean>
     
    </beans>

    Voilà, je ne comprends pas doit se faire ce fameux "mapping manquant".

    Avez-vous une idée ?

    Merci =D.

    Edit : Bon, j'ai trouvé... Le Adresse de "session.createQuery("FROM Adresse").list();" doit être le nom de la classe et pas le nom de la table. Voilà, c'était un problème de majuscule...

  2. #2
    Membre confirmé
    Inscrit en
    Octobre 2005
    Messages
    136
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 136
    Par défaut
    De mémoire le HQL est sensible à la case.
    essaye comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    List<Utilisateur> res = session.createQuery("from Utilisateur").list();

  3. #3
    Membre Expert
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    2 962
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 962
    Par défaut
    Citation Envoyé par bilgetz Voir le message
    De mémoire le HQL est sensible à la case.
    14.1. Case Sensitivity


    With the exception of names of Java classes and properties, queries are case-insensitive. So SeLeCT is the same as sELEct is the same as SELECT, but org.hibernate.eg.FOO is not org.hibernate.eg.Foo, and foo.barSet is notfoo.BARSET.This manual uses lowercase HQL keywords. Some users find queries with uppercase keywords more readable, but this convention is unsuitable for queries embedded in Java code.




+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 6
    Dernier message: 08/07/2010, 23h04
  2. Hibernate annotation: class not mapped
    Par Babilion dans le forum Hibernate
    Réponses: 7
    Dernier message: 25/03/2010, 22h54
  3. Réponses: 0
    Dernier message: 15/05/2009, 12h13
  4. hibernate problem (classe not mapped)
    Par oughlad dans le forum Hibernate
    Réponses: 11
    Dernier message: 25/06/2007, 19h57
  5. [Hibernate][Spring] Session Hibernate initialisée
    Par mauvais_karma dans le forum Hibernate
    Réponses: 12
    Dernier message: 08/08/2005, 13h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo