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

JPA Java Discussion :

Tutoriel Persistance Java 5


Sujet :

JPA Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    277
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 277
    Par défaut Tutoriel Persistance Java 5
    Bonjour,

    J’effectue la mise en place du tutoriel « Persistance Java 5 » de Serge Tahé. Malheureusement je rencontres plusieurs problèmes.
    Mes taches de ante ne fonctionnent pas, voici le résultat du tutoriel quand la tache DLL est lancée :

    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
    9. D DL:
    10. [hibernatetool] Executing Hibernate Tool with a JPA Configuration
    11. [hibernatetool] 1. task: hbm2ddl (Generates database schema)
    12. [hibernatetool] drop table if exists jpa01_personne;
    13. [hibernatetool] create table jpa01_personne (
    14. [hibernatetool] ID integer not null auto_increment,
    15. [hibernatetool] VERSION integer not null,
    16. [hibernatetool] NOM varchar(30) not null unique,
    17. [hibernatetool] PRENOM varchar(30) not null,
    18. [hibernatetool] DATENAISSANCE date not null,
    19. [hibernatetool] MARIE bit not null,
    20. [hibernatetool] NBENFANTS integer not null,
    21. [hibernatetool] primary key (ID)
    22. [hibernatetool] ) ENGINE=InnoDB;
    23. BUILD SUCCESSFUL
    24. Total time: 5 seconds
    Alors que lorsque je lance la tache le fichier schema.sql n’est pas écrit et le résultat en console est le suivant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    DDL:
    [hibernatetool] Executing Hibernate Tool with a JPA Configuration
    [hibernatetool] 1. task: hbm2ddl (Generates database schema)
    BUILD SUCCESSFUL
    Total time: 10 seconds
    Quand j’exécute la classe InitDB voici l’erreur que j’ai en console quand 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
    21
    22
    23
    24
    25
    26
    27
     
    Exception in thread "main" java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Personne is not mapped [select p from Personne p order by p.nom asc]
    	at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:634)
    	at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:95)
    	at tests.InitDB.main(Unknown Source)
    Caused by: org.hibernate.hql.ast.QuerySyntaxException: Personne is not mapped [select p from Personne p order by p.nom asc]
    	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:265)
    	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 org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:92)
    	... 1 more
    Si je commente le code suivant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    		for (Object p : em.createQuery("select p from Personne p order by p.nom asc").getResultList()) {
    			System.out.println(p);
    		}
    J’ai une exception de persistance dans le code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Hibernate: 
        delete 
        from
            jpa01_personne
    Exception in thread "main" java.lang.IllegalArgumentException: Unknown entity: entites.Personne
    	at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:215)
    	at tests.InitDB.main(InitDB.java:37)
    J’ai bien effectuer l’importation du projet.


    Je vous remercie d’avance.

    Cordialement, Luis Parente.

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    277
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 277
    Par défaut
    J'ai trouvé le problème, dans le fichier persistence.xml dont le contenu est:

    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
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
    	<persistence-unit name="jpa" transaction-type="RESOURCE_LOCAL">
    	<class>entites.Personne</class>
    	   <!--  provider -->
    		<provider>org.hibernate.ejb.HibernatePersistence</provider>
    		<properties>
    			<!-- Classes persistantes -->
    			<property name="hibernate.archive.autodetection" value="class, hbm" />
     
    				<property name="hibernate.show_sql" value="true"/>
    				<property name="hibernate.format_sql" value="true"/>
    				<property name="use_sql_comments" value="true"/>
     
    			<!-- connexion JDBC -->
    			<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
    			<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jpa" />
    			<property name="hibernate.connection.username" value="jpa" />
    			<property name="hibernate.connection.password" value="jpa" />
    			<!--  création automatique du schéma -->
    			<property name="hibernate.hbm2ddl.auto" value="create" />
    			<!-- Dialecte -->
    			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
    			<!--  propriétés DataSource c3p0 -->
    			<property name="hibernate.c3p0.min_size" value="5" />
    			<property name="hibernate.c3p0.max_size" value="20" />
    			<property name="hibernate.c3p0.timeout" value="300" />
    			<property name="hibernate.c3p0.max_statements" value="50" />
    			<property name="hibernate.c3p0.idle_test_period" value="3000" />
    		</properties>
    	</persistence-unit>
    </persistence>
    j'ai ajouté la balise suivante
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <class>entites.Personne</class>
    et voilà

    a+

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 22
    Par défaut
    J'ai passé une demi journée à trouver ce qui clochait

    merci

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

Discussions similaires

  1. Est ce possible de parser un Fichier XML généré avec la persistance JAVA
    Par hbellahc dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 31/08/2007, 14h23
  2. Tutoriel ressources Java ?
    Par Jahjouh dans le forum Langage
    Réponses: 13
    Dernier message: 11/12/2006, 15h23

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