Bonjour,
Tout est dans le titre. Je voudrais découvrir hibernate avec netbeans, j'ai donc été sur le site de netbeans et j'ai trouvé ce tuto: http://netbeans.org/kb/docs/web/hibernate-webapp.html
Je suis le tuto et lorsque j'utilise Hql pour récupérer les films (section "Enumerating Film Titles and Retrieving Actors Using an HQL Query" du tuto) ça coince.
Je me prend l'exception:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
org.hibernate.hql.ast.QuerySyntaxException: Film is not mapped [from Film]
J'ai récupéré le projet final du site, et avec ce projet là cela coince aussi.
Voici les différents fichiers:
hibernate.cfg
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
<hibernate-configuration>
  <session-factory>
    <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/sakila</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">root</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <mapping resource="dvdrental/FilmActor.hbm.xml"/>
    <mapping resource="dvdrental/FilmCategory.hbm.xml"/>
    <mapping resource="dvdrental/Category.hbm.xml"/>
    <mapping resource="dvdrental/Language.hbm.xml"/>
    <mapping resource="dvdrental/Film.hbm.xml"/>
    <mapping resource="dvdrental/Actor.hbm.xml"/>
  </session-factory>
</hibernate-configuration>
hibernate.reveng
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
<hibernate-reverse-engineering>
  <schema-selection match-catalog="sakila"/>
  <table-filter match-name="film"/>
  <table-filter match-name="language"/>
  <table-filter match-name="film_category"/>
  <table-filter match-name="category"/>
  <table-filter match-name="film_actor"/>
  <table-filter match-name="actor"/>
</hibernate-reverse-engineering>
film.hbm
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
<hibernate-mapping>
    <class name="dvdrental.Film" table="film" catalog="sakila">
        <id name="filmId" type="java.lang.Short">
            <column name="film_id" />
            <generator class="identity" />
        </id>
        <many-to-one name="languageByOriginalLanguageId" class="dvdrental.Language" fetch="select">
            <column name="original_language_id" />
        </many-to-one>
        <many-to-one name="languageByLanguageId" class="dvdrental.Language" fetch="select">
            <column name="language_id" not-null="true" />
        </many-to-one>
        <property name="title" type="string">
            <column name="title" not-null="true" />
        </property>
        <property name="description" type="string">
            <column name="description" length="65535" />
        </property>
        <property name="releaseYear" type="date">
            <column name="release_year" length="0" />
        </property>
        <property name="rentalDuration" type="byte">
            <column name="rental_duration" not-null="true" />
        </property>
        <property name="rentalRate" type="big_decimal">
            <column name="rental_rate" precision="4" not-null="true" />
        </property>
        <property name="length" type="java.lang.Short">
            <column name="length" />
        </property>
        <property name="replacementCost" type="big_decimal">
            <column name="replacement_cost" precision="5" not-null="true" />
        </property>
        <property name="rating" type="string">
            <column name="rating" length="5" />
        </property>
        <property name="specialFeatures" type="string">
            <column name="special_features" length="54" />
        </property>
        <property name="lastUpdate" type="timestamp">
            <column name="last_update" length="19" not-null="true" />
        </property>
        <set name="filmActors" inverse="true">
            <key>
                <column name="film_id" not-null="true" />
            </key>
            <one-to-many class="dvdrental.FilmActor" />
        </set>
        <set name="filmCategories" inverse="true">
            <key>
                <column name="film_id" not-null="true" />
            </key>
            <one-to-many class="dvdrental.FilmCategory" />
        </set>
    </class>
</hibernate-mapping>
et la classe Film
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
public class Film  implements java.io.Serializable {
 
 
     private Short filmId;
     private Language languageByOriginalLanguageId;
     private Language languageByLanguageId;
     private String title;
     private String description;......
Je ne vois pas ou cela cloche. J'ai essayé:
  • la différence de casse pour coller au fichier hibernate.reveng
  • d'ajouter l'attribut package à la balise hibernate-mapping du fichier Film.hbm

Je connais le Hql: par exemple pour obtenir la liste des titres de film:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
select film.title From Film film
je l'ai essayé aussi, et sans succès

Comme je découvre hibernate, je ne vois pas ce que j'ai manqué.

Faut-il ajouter l'annotation @Entity dans la classe? Chose que je trouverai étrange , vu que tout est défini dans le hbm.

Quelqu'un pourrait-il m'aider? Me dire ce qui ne va pas du tout.
Merci beaucoup