QuerySyntaxException: [table is not mapped]
Salut à tous je débute sur Hibernate, jai configuré ma base de donnée les fichier de configuration sont correct mais mistere###? je suis sur netbeans voici mes config : j'essaye de faire une simple requette
Code:
select nom form users
et ça ne passe pas, il me dis que ma table table n'est pas #mapped#, or ds la config tout me semble correct.
l'insertion dans la table se deroule ss probleme. merci d'avance
Code:
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
| <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class dynamic-insert="false"
dynamic-update="false"
mutable="true"
name="metier.Users"
optimistic-lock="version"
polymorphism="implicit"
select-before-update="false"
table="users">
<id column="idusers" name="IDUSERS" type="integer" >
<generator class="increment" />
</id>
<property name="LOGIN" column="login" type="string" >
</property>
<property name="NOM" column="nom" type="string" >
</property>
<property name="PRENOM" column="prenom" type="string" >
</property>
<property name="PASSWD" column="passwd" type="string" >
</property>
</class>
</hibernate-mapping> |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| <?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 name="Hisession">
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/word_jsf</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<mapping resource="uers.hbm.xml" package="metier" class="metier.Users"/>
</session-factory>
</hibernate-configuration> |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| private static void listUsers() {
Transaction tx = null;
SessionFactory fact = new Configuration().configure().buildSessionFactory();
Session session = fact.openSession();
try {
tx = session.beginTransaction();
List honeys = session.createQuery("select nom from users").list();
for (Iterator iter = honeys.iterator(); iter.hasNext();) {
Users element = (Users) iter.next();
System.out.println("nom : " + element.getNOM());
}
tx.commit();
} catch (Exception e) {
e.printStackTrace();
if (tx != null && tx.isActive()) {
tx.rollback();
}
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| org.hibernate.hql.ast.QuerySyntaxException: users is not mapped [select nom from users]
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:255)
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 metier.Tester.listUsers(Tester.java:93)
at metier.Tester.main(Tester.java:37)
BUILD SUCCESSFUL (total time: 2 seconds) |
Merci