IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Hibernate Java Discussion :

Tutoriel netbeans "Using Hibernate in a Web Application" qui pose probleme: "Film not mapped"


Sujet :

Hibernate Java

  1. #1
    Membre habitué Avatar de touftouf57
    Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2007
    Messages
    362
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2007
    Messages : 362
    Points : 174
    Points
    174
    Par défaut Tutoriel netbeans "Using Hibernate in a Web Application" qui pose probleme: "Film not mapped"
    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

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Décembre 2003
    Messages
    476
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2003
    Messages : 476
    Points : 595
    Points
    595
    Par défaut
    Salut,

    A priori, le tout semble bon.
    Tu as regardé dans les logs hibernate au démarage de ton appli si ton entité est bien reconnue ?

    Au niveau debug, tu devrais voir les entités chargées par hibernate lors de l'initialisation de son contexte.
    Si tu vois pas ton entité, ni d'anomalies dans les logs hibernate, c'est que ton entité n'est pas chargé au démarrage. Aussi, Revois plutôt ta configuration.

  3. #3
    Membre habitué Avatar de touftouf57
    Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2007
    Messages
    362
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2007
    Messages : 362
    Points : 174
    Points
    174
    Par défaut
    Merci d'avoir jeter un oeil.

    Bon le projet télécharger depuis le site de netbeans fonctionne.

    Mais cela fait 2 heures que je cherche les différences entre les 2 projets et je n'en vois aucune.

    Tu me dis de vérifier ma configuration. J'ai vérifié mes sun-web.xml et web.xml et ils sont identiques excepté les doctype. Je les ai changé et toujours ce message "invalid query" lorsque je tape "from Film".

    Quand je déploie l'appli je n'ai aucune entité de chargé.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    INFO: Initialisation de Mojarra 2.0.2 (FCS b10) pour le contexte '/DVDStoreTuto'
    INFO: Loading application DVDStoreTuto at /DVDStoreTuto
    INFO: DVDStoreTuto was successfully deployed in 1*934 milliseconds.
    alors que je l'ai bien lorsque je déploie l'appli du tutoriel
    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
     
    INFO: Initialisation de Mojarra 2.0.2 (FCS b10) pour le contexte '/DVDStore'
    INFO: Loading application DVDStore at /DVDStore
    INFO: DVDStore was successfully deployed in 1*929 milliseconds.
    INFO: Hibernate Annotations 3.3.1.GA
    INFO: Hibernate 3.2.5
    INFO: hibernate.properties not found
    INFO: Bytecode provider name : cglib
    INFO: using JDK 1.4 java.sql.Timestamp handling
    INFO: configuring from resource: /hibernate.cfg.xml
    INFO: Configuration resource: /hibernate.cfg.xml
    INFO: Reading mappings from resource : dvdrental/FilmActor.hbm.xml
    INFO: Reading mappings from resource : dvdrental/FilmCategory.hbm.xml
    INFO: Reading mappings from resource : dvdrental/Category.hbm.xml
    INFO: Reading mappings from resource : dvdrental/Language.hbm.xml
    INFO: Reading mappings from resource : dvdrental/Film.hbm.xml
    INFO: Reading mappings from resource : dvdrental/Actor.hbm.xml
    INFO: Configured SessionFactory: null
    INFO: Mapping class: dvdrental.FilmActor -> film_actor
    INFO: Mapping class: dvdrental.FilmCategory -> film_category
    INFO: Mapping class: dvdrental.Category -> category
    INFO: Mapping class: dvdrental.Language -> language
    INFO: Mapping class: dvdrental.Film -> film
    INFO: Mapping class: dvdrental.Actor -> actor
    INFO: Mapping collection: dvdrental.Category.filmCategories -> film_category
    INFO: Mapping collection: dvdrental.Language.filmsForOriginalLanguageId -> film
    INFO: Mapping collection: dvdrental.Language.filmsForLanguageId -> film
    INFO: Mapping collection: dvdrental.Film.filmActors -> film_actor
    INFO: Mapping collection: dvdrental.Film.filmCategories -> film_category
    INFO: Mapping collection: dvdrental.Actor.filmActors -> film_actor
    Ou dois-je encore fouillé?
    Merci

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Décembre 2003
    Messages
    476
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2003
    Messages : 476
    Points : 595
    Points
    595
    Par défaut
    La configuration c'est aussi la structure du projet : l'endroit ou tu as mis tes fichiers (classpath ou non), la version des libs etc...

    Tes logs donnent l'impression que ton fichier de conf hibernate n'est pas utilisé.
    Rajoute un mapping qui n'existe pas dedans :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
        <mapping resource="dvdrental/Nimportequoi.hbm.xml"/>
    Normalement, ca devrait péter à l'initialisation du contexte Hibernate.
    Si ca pete pas, c'est que c'est pas utilisé.
    Comment as tu lié ton fichier de conf hibernate.cfg à la création de la sessionfactory qui te permet de faire la requete qui ne trouve rien ? La classe configuration? autre chose ?
    Fais nous voir cette partie de code.

  5. #5
    Membre habitué Avatar de touftouf57
    Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2007
    Messages
    362
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2007
    Messages : 362
    Points : 174
    Points
    174
    Par défaut
    Bon j'ai recommencé le tuto, et au moment de tester le fameux "from Film", j'ai tout simplement fait un build du projet et ça a fonctionné. Sans ce build cela ne marchait pas.

    Tu me demandes comment j'ai lié mon fichier de configuration hibernate.cfg.xml à la sessionFactory, et bien j'ai fait cela comme dans le tuto, en créant une class HibernateUtil dont voici le code:
    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
     
    public class HibernateUtil {
        private static final SessionFactory sessionFactory;
     
        static {
            try {
                // Create the SessionFactory from standard (hibernate.cfg.xml) 
                // config file.
                sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
            } catch (Throwable ex) {
                // Log the exception. 
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }
        }
     
        public static SessionFactory getSessionFactory() {
            return sessionFactory;
        }
    }
    Ce problème restera un mystère pour moi, mais bon cela a été résolu et je ne sais pas comment
    En tout cas merci thebloodyman

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Décembre 2003
    Messages
    476
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2003
    Messages : 476
    Points : 595
    Points
    595
    Par défaut
    De rien

    Cool que ca se soit arrangé
    Étrange comme plus souvent qu'on le croit en dev

    Je ne sais pas si t'as conservé le projet qui ne fonctionnait pas.
    Si c'est le cas, tu peux faire une comparaison depuis ton ide des 2 projets pour voir les différences ( je sais ps si Netbeans te le permet. Eclipse oui en tout cas).

  7. #7
    Membre habitué Avatar de touftouf57
    Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2007
    Messages
    362
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2007
    Messages : 362
    Points : 174
    Points
    174
    Par défaut
    Je n'ai pas gardé l'ancien projet. Cependant je ne vois pas de différence (de mémoire) entre le nouveau et l'ancien.

    Et netbeans te permet de comparer 2 fichiers (clic droit sur le fichier --> tool --> diff to). Je m'en était servi justement pour comparer le projet qui ne fonctionnait pas et celui fourni sur le site.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Les Tutoriels NetBeans
    Par mlny84 dans le forum NetBeans
    Réponses: 13
    Dernier message: 09/11/2012, 13h13
  2. Réponses: 0
    Dernier message: 09/10/2010, 17h32
  3. Réponses: 10
    Dernier message: 12/12/2006, 01h44
  4. déploiement d'une WEB application développée par Netbeans
    Par diamonds dans le forum Tomcat et TomEE
    Réponses: 4
    Dernier message: 28/11/2006, 18h42
  5. hibernate with web application
    Par oughlad dans le forum Hibernate
    Réponses: 5
    Dernier message: 15/05/2006, 13h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo