Bonjour, j'essaie d'implémenter hibernate sur une de mes applis web, je l'ai fait via netbeans, par contre netbeans n'a pas voulu me générer mes Classes/fichier hbm avec son outil, j'ai donc tout fait à la main
Je test une requête HQL
J'ai cette erreur :
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
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
	at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123)
	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:89)
	at org.hibernate.loader.Loader.getResultSet(Loader.java:2065)
	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1862)
	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)
	at org.hibernate.loader.Loader.doQuery(Loader.java:909)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
	at org.hibernate.loader.Loader.doList(Loader.java:2551)
	at org.hibernate.loader.Loader.doList(Loader.java:2537)
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2367)
	at org.hibernate.loader.Loader.list(Loader.java:2362)
	at org.hibernate.hql.internal.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:939)
	at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:229)
	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1260)
	at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "from"
  Position*: 9
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:559)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:80)
	... 15 more
je pense pas que la syntaxe soit mauvaise, il doit y avoir un autre problème.
hibernate.cfg.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
<?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.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
    <property name="hibernate.connection.url">jdbc:postgresql://127.0.0.1:5432/xxxxxxxxxx</property>
    <property name="hibernate.connection.username">xxxxxxxxxxxxx</property>
    <property name="hibernate.connection.password">xxxxxxxxxx</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <property name="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</property>
    <mapping class="hibernate.TUsers" package="hibernate" resource="hibernate/users.hbm.xml"/>
    <mapping class="hibernate.TActualIdAnchor" file="" jar="" package="hibernate" resource="hibernate/actual_id_anchor.hbm.xml"/>
    <mapping class="hibernate.TActualIdBacklink" file="" jar="" package="hibernate" resource="hibernate/actual_id_backlink.hbm.xml"/>
    <mapping class="hibernate.TAnchor" file="" jar="" package="hibernate" resource="hibernate/anchor.hbm.xml"/>
    <mapping class="hibernate.TCategory" file="" jar="" package="hibernate" resource="hibernate/category.hbm.xml"/>
    <mapping class="hibernate.TCategorySite" file="" jar="" package="hibernate" resource="hibernate/category_site.hbm.xml"/>
    <mapping class="hibernate.TCodeMdp" file="" jar="" package="hibernate" resource="hibernate/code_mdp.hbm.xml"/>
    <mapping class="hibernate.TSite" file="" jar="" package="hibernate" resource="hibernate/site.hbm.xml"/>
    <mapping/>
  </session-factory>
</hibernate-configuration>
TUsers.java
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package hibernate;
 
import classes.SuperClass;
import java.io.Serializable;
 
/**
 *
 * @author marie
 */
public class TUsers extends SuperClass implements Serializable {
 
    protected long id;
    protected String email;
    protected String mdp;
    protected String cookie_code;
 
    /**
     * @return the id
     */
    public long getId() {
        return id;
    }
 
    /**
     * @param id the id to set
     */
    public void setId(long id) {
        this.id = id;
    }
 
    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }
 
    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }
 
    /**
     * @return the mdp
     */
    public String getMdp() {
        return mdp;
    }
 
    /**
     * @param mdp the mdp to set
     */
    public void setMdp(String mdp) {
        this.mdp = mdp;
    }
 
    /**
     * @return the cookie_code
     */
    public String getCookie_code() {
        return cookie_code;
    }
 
    /**
     * @param cookie_code the cookie_code to set
     */
    public void setCookie_code(String cookie_code) {
        this.cookie_code = cookie_code;
    }
}
users.hbm.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
<?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 name="hibernate.TUsers" table="users">
        <id name="id" type="long">
            <generator class="increment"/>
        </id>
        <property name="email" column="email" type="string"/>
        <property name="mdp" column="mdp" type="string"/>
        <property name="cookie_code" column="cookie_code" type="string"/>
    </class>
</hibernate-mapping>
Merci !