Bonjour à tous,
j'ai un petit problème lorsque je lance mon projet :
L'erreur provient de la méthode recupererUtilisateurs() de la classe UtilisateurDaoImpl (la méthode d'insertion fonctionne) :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)
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 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; } }
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 @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; } }
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 où 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...
Partager