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 :

(eclipse,hibernate) NoClassDefFoundError dans un projet JPA


Sujet :

JPA Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éprouvé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2006
    Messages
    958
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Janvier 2006
    Messages : 958
    Par défaut (eclipse,hibernate) NoClassDefFoundError dans un projet JPA
    salut,

    je cherche à tester JPA, avec eclipse, hibernate.
    j'ai créé un projet JPA (j'utiliser eclipse JEE) contenant une entity personne, et deux clases contenant une méthode main pour les tests.
    (le tout est fourni plus loin mais ce n'est je crois pas très important car le problème ne vient pas de là).

    le problème - j'y arrive - est que je n'arrive pas à faire correctement reconnaître hibernate.

    à l'execution j'ai le message suivant:

    Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/ReflectionManager
    at org.hibernate.ejb.Ejb3Configuration.<init>(Ejb3Configuration.java:127)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:119)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
    at tests.InitDB.main(InitDB.java:19)
    Caused by: java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.ReflectionManager
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    ... 5 more
    je pense que le problème vient de l'intégration d'hibernate avec le projet, ce que j'ai fait c'est de télécharger hibernate-core sur le site d'hibernate et de copier les jars dans une librairie utilisateur, et d'incorporer cette dernière dans le projet.

    mais je m'y suis peut-être mal pris (j'ai peut-être oublié des fichiers).
    pouvez-vous me dire quels fichiers jars copier dans la librairie, et quels fichiers télécharger à partir du site d'hibernate(hibernate-annotations...)
    aussi je crois qu'il y a une fichier javaee.jar à inclure mais je ne sais pas d'où...

    olivier.

    NB:
    fichier Pesonne.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
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    package entites;
     
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Locale;
     
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
    import javax.persistence.Version;
     
    @SuppressWarnings("unused")
    @Entity
    public class Personne {
     
    	@Id
    	@Column(name = "ID", nullable = false)
    	@GeneratedValue(strategy = GenerationType.AUTO)
    	private Integer id;
     
    	@Column(name = "VERSION", nullable = false)
    	@Version
    	private int version;
     
    	@Column(name = "NOM", length = 30, nullable = false, unique = true)
    	private String nom;
     
    	@Column(name = "PRENOM", length = 30, nullable = false)
    	private String prenom;
     
    	@Column(name = "DATENAISSANCE", nullable = false)
    	@Temporal(TemporalType.DATE)
    	private Date datenaissance;
     
    	@Column(name = "MARIE", nullable = false)
    	private boolean marie;
     
    	@Column(name = "NBENFANTS", nullable = false)
    	private int nbenfants;
     
    	// constructeurs
    	public Personne() {
    	}
     
    	public Personne(String nom, String prenom, Date datenaissance, boolean marie,
    			int nbenfants) {
    		setNom(nom);
    		setPrenom(prenom);
    		setDatenaissance(datenaissance);
    		setMarie(marie);
    		setNbenfants(nbenfants);
    	}
     
    	// toString
    	public String toString() {
    		return String.format("[%d,%d,%s,%s,%s,%s,%d]", getId(), getVersion(),
    				getNom(), getPrenom(), new SimpleDateFormat("dd/MM/yyyy")
    						.format(getDatenaissance()), isMarie(), getNbenfants());
    	}
     
    	// getters and setters
    	public Integer getId() {
    		return id;
    	}
     
    	private void setId(Integer id) {
    		this.id = id;
    	}
     
    	public int getVersion() {
    		return version;
    	}
     
    	private void setVersion(int version) {
    		this.version = version;
    	}
     
    	public String getNom() {
    		return nom;
    	}
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	public String getPrenom() {
    		return prenom;
    	}
     
    	public void setPrenom(String prenom) {
    		this.prenom = prenom;
    	}
     
    	public Date getDatenaissance() {
    		return datenaissance;
    	}
     
    	public void setDatenaissance(Date datenaissance) {
    		this.datenaissance = datenaissance;
    	}
     
    	public boolean isMarie() {
    		return marie;
    	}
     
    	public void setMarie(boolean marie) {
    		this.marie = marie;
    	}
     
    	public int getNbenfants() {
    		return nbenfants;
    	}
     
    	public void setNbenfants(int nbenfants) {
    		this.nbenfants = nbenfants;
    	}
    }
    fichier initDB.java (qui contient main)
    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
    package tests;
     
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
     
    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.EntityTransaction;
    import javax.persistence.Persistence;
     
    import entites.Personne;
     
    public class InitDB {
    	// constantes
    	private final static String TABLE_NAME = "jpa01_personne";
     
    	public static void main(String[] args) throws ParseException {
    		// récupérer un EntityManagerFactory à* partir de l'unité de persistance
    		EntityManagerFactory emf = Persistence.createEntityManagerFactory("personne1");
    		// récupérer un EntityManager à* partir de l'EntityManagerFactory
    		EntityManager em = emf.createEntityManager();
    		// début transaction
    		EntityTransaction tx = em.getTransaction();
    		tx.begin();
    		// supprimer les éléments de la table PERSONNE
    		em.createNativeQuery("delete from " + TABLE_NAME).executeUpdate();
    		// mettre des éléments dans la table PERSONNE
    		Personne p1 = new Personne("Martin", "Paul", new SimpleDateFormat("dd/MM/yy").parse("31/01/2000"), true, 2);
    		Personne p2 = new Personne("Durant", "Sylvie", new SimpleDateFormat("dd/MM/yy").parse("05/07/2001"), false, 0);
    		// persistance des personnes
    		em.persist(p1);
    		em.persist(p2);
    		// affichage personnes
    		System.out.println("[personnes]");
    		for (Object p : em.createQuery("select p from Personne p order by p.nom asc").getResultList()) {
    			System.out.println(p);
    		}
    		// fin transaction
    		tx.commit();
    		// fin EntityManager
    		em.close();
    		// fin EntityManagerFactory
    		emf.close();
    		// log
    		System.out.println("terminé ...");
    	}
    }
    fichier persistence.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
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    	<persistence-unit name="personne1" transaction-type="RESOURCE_LOCAL">
    		<!--  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/jbossdb" />
    			<property name="hibernate.connection.username" value="id" />
    			<property name="hibernate.connection.password" value="password" />
    			<!--  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>
    voilà, j'éspère que cela vous servira(voir aussi la photo jointe).

  2. #2
    Membre éprouvé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2006
    Messages
    958
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Janvier 2006
    Messages : 958
    Par défaut
    du nouveau!
    en ajoutant des jars (un peu au hasard )j'ai un autre message d'erreur à l'exécution:

    Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named personne1
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:56)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
    at tests.InitDB.main(InitDB.java:19)
    c'est mieux ou moins bien?

    olivier.

Discussions similaires

  1. Réponses: 9
    Dernier message: 17/04/2014, 12h38
  2. Compiler un projet JPA dans Eclipse
    Par the watcher dans le forum Build
    Réponses: 0
    Dernier message: 25/03/2011, 18h46
  3. Réponses: 2
    Dernier message: 03/07/2006, 20h14
  4. [Info] ajout de fichier dans des projets eclipse
    Par root76 dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 16/12/2005, 12h48
  5. Réponses: 2
    Dernier message: 26/09/2005, 08h29

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