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!