These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Récupération dune liste --> 'nomDeLaClasse' is not mapp
PostPosted: Mon Nov 20, 2006 5:08 pm 
Newbie

Joined: Mon Nov 20, 2006 4:50 pm
Posts: 2
Bonjour,
Je débute totalement ... Ne criez pas trp fort svp... ;-)

Voila je cherche à récupérer une liste des noms des utilisateurs de ma BDD (mysql).

Le code utilisé à l'intérieur de mon Main est le suivant :

Code:
Session session = HibernateUtil.currentSession();
List list = session.createQuery("select nom from utilisateur where nom= ?").setString(0, "nom").list();
Iterator it = list.iterator();
while(it.hasNext()) {
Utilisateur unUtilisateur = (Utilisateur)it.next();
System.out.println(unUtilisateur.getNom()); }
HibernateUtil.closeSession();



Au lancement, problème !

Quote:
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: utilisateur is not mapped [select nom from utilisateur where nom= ?]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:257)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at applicatifLFD.Test.main(Test.java:44)


Pour information, mon fichier Utilisateur.hbm.xml est :

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="donnees">
   <class name="Utilisateur" table="utilisateur">
      <meta attribute="sync-DAO">false</meta>
      <id name="Id" type="integer" column="id"><generator class="increment"/></id>
      <!--<property name="IdProfil" column="id_profil" type="integer" not-null="true" length="11"/>-->
      <property name="Nom" column="nom" type="string" not-null="true" length="32"/>
      <property name="Prenom" column="prenom" type="string" not-null="true" length="32"/>
      <property name="Login" column="login" type="string" not-null="true" length="8"/>
      <property name="Mdp" column="mdp" type="string" not-null="true" length="8"/>
   </class>   
</hibernate-mapping>


et hibernate.cfg.xml :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
   <session-factory>
      <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.password">master</property>
      <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/LFD</property>
      <property name="hibernate.connection.username">master</property>
      <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
      <property name="current_session_context_class">thread</property>
      <property name="hibernate.show_sql">true</property>
      <mapping resource="Utilisateur.hbm.xml" />
      <mapping resource="Role.hbm.xml" />
   </session-factory>
</hibernate-configuration>


Je ne'arrive pas à cerner le problème....
Si quelqu'un veut bien me faire profiter de sa lumière....
Merci d'avance!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 8:54 pm 
Newbie

Joined: Mon Nov 20, 2006 4:50 pm
Posts: 2
J'ai un peu avancé grâce à une réponse sur le forum de 'développez.net'.
L'erreur venait du nommage dans ma requête, il fallait mettre 'Utilisateur' avec une majuscule (nom de la classe et non de la table... requête HQL oblige!) .

Dorénavant, en lieu et place des messages d'erreurs précédents (la console donc ...) :

Code:
Hibernate: select utilisateu0_.nom as col_0_0_ from utilisateur utilisateu0_ where utilisateu0_.nom=?



J'ai essayé différentes choses, notamment de mettre, ou pas, le nom de la propriété 'nom' en majuscule à différents endroits (dans la requête, en paramètre du setString)...

Pour l'instant, choux blanc!

J'ai pourtant consulté le manuel de référence (pas tout lu encore... mais au moins ce qui concerne le requêtage HQL)et, encore une fois, je ne comprends pas où ça coince....

Merci d'avance.....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 21, 2006 9:35 am 
Newbie

Joined: Tue Nov 21, 2006 9:26 am
Posts: 2
En faisant "select nom from Utilisateur", tu vas récupérer une liste de string et nom pas des objets "Utilisateur".
Pour ce, par exemple, tu peux essayer :
List list = session.createQuery(" from Utilisateur where nom= ?").setString(0, "nom").list();

JBV


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.