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 :

No Persistence provider for EntityManager.


Sujet :

JPA Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Analyste programmeur
    Inscrit en
    Octobre 2010
    Messages
    122
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Belgique

    Informations professionnelles :
    Activité : Analyste programmeur

    Informations forums :
    Inscription : Octobre 2010
    Messages : 122
    Par défaut No Persistence provider for EntityManager.
    Bonjour,

    Je débute avec JPA.

    Je reçoit déjà un message d'erreur quand je lancement mon application

    J'utilise le serveur MySql pour mes base de données.

    Pourriez- vous me données une solution ou des pistes à suivre.

    Merci

    L'erreur qui est jeté:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    log4j:WARN No appenders could be found for logger (org.hibernate.ejb.Version).
    log4j:WARN Please initialize the log4j system properly.
    Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named helloworld
    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
    	at Application.main(Application.java:14)
    le fichier de persistence:
    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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence     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"    version="1.0">
    	<persistence-unit name="helloworld" transaction-type="RESOURCE_LOCAL">
    		<!--  provider>org.hibernate.ejb.HibernatePersistence</provider>
    		<class>helloworld.Message</class-->
    		<properties>
    			<property name="hibernate.archive.autodetection" value="class"/>
    			<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
    			<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jpa1helloworld"/>
    		    <property name="hibernate.connection.username" value="root"/>
    		    <property name="hibernate.connection.password" value="root"/>
    		    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
    		    <property name="hibernate.show_sql" value="true"/>
    		    <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
    		</properties>
    	</persistence-unit>
    </persistence>
    et l'application
    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
     
    import helloworld.Message;
     
    import java.util.List;
     
    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.EntityTransaction;
    import javax.persistence.Persistence;
     
    public class Application {
     
    	public static void main(String[] args) {
    		// same in xml file
    		EntityManagerFactory emf = Persistence.createEntityManagerFactory("helloworld");
    		EntityManager em = emf.createEntityManager();
    		EntityTransaction tx = em.getTransaction();
    		tx.begin();
    		Message message = new Message();
    		message.setText("Using JPA with Hibernate");
    		em.persist(message);
    		Message message2 = new Message();
    		message2.setText("Hello World");
    		em.persist(message2);
    		tx.commit();
    		em.close();
     
    		EntityManager newEm = emf.createEntityManager();
    		EntityTransaction newTx = newEm.getTransaction();
    		newTx.begin();
    		List messages = newEm.createQuery("select m from Message m order by m.text asc").getResultList();
    		System.out.println(messages.size() + "message(s) found:");
    		for(Object m : messages){
    			Message loadedMsg = (Message)m;
    			System.out.println(loadedMsg.getText());
    		}
    		newTx.commit();
    		newEm.close();
    		emf.close();
    	}
     
    }

  2. #2
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 2 938
    Par défaut
    Il est dans quel repertoire ton persistence.xml?

  3. #3
    Membre confirmé
    Homme Profil pro
    Analyste programmeur
    Inscrit en
    Octobre 2010
    Messages
    122
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Belgique

    Informations professionnelles :
    Activité : Analyste programmeur

    Informations forums :
    Inscription : Octobre 2010
    Messages : 122
    Par défaut
    Citation Envoyé par DevServlet Voir le message
    Il est dans quel repertoire ton persistence.xml?
    /jpa1helloworld/src/resources/META-INF/persistence.xml

  4. #4
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 2 938
    Par défaut
    Essaie ca :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    @PersistenceContext(unitName="helloworld")
    private EntityManager em;

  5. #5
    Membre confirmé
    Homme Profil pro
    Analyste programmeur
    Inscrit en
    Octobre 2010
    Messages
    122
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Belgique

    Informations professionnelles :
    Activité : Analyste programmeur

    Informations forums :
    Inscription : Octobre 2010
    Messages : 122
    Par défaut
    J'ai ouvert un projets JPA.

    et voici ce qui m'affiche

    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
    [EL Info]: 2011-07-25 14:38:08.234--ServerSession(23387093)--EclipseLink, version: Eclipse Persistence Services - 1.1.3.v20091002-r5404
    [EL Severe]: 2011-07-25 14:38:08.25--ServerSession(23387093)--Local Exception Stack: 
    Exception [EclipseLink-4021] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.DatabaseException
    Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null].  Verify that you have set the expected driver class and URL.  Check your login, persistence.xml or sessions.xml resource.  The jdbc.driver property should be set to a class that is compatible with your database platform
    	at org.eclipse.persistence.exceptions.DatabaseException.unableToAcquireConnectionFromDriverException(DatabaseException.java:375)
    	at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:90)
    	at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:583)
    	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:227)
    	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:255)
    	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:112)
    	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:164)
    	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:151)
    	at model.EmployeeTest.main(EmployeeTest.java:12)
     
    Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-4021] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.DatabaseException
    Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null].  Verify that you have set the expected driver class and URL.  Check your login, persistence.xml or sessions.xml resource.  The jdbc.driver property should be set to a class that is compatible with your database platform
    	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:272)
    	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:112)
    	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:164)
    	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:151)
    	at model.EmployeeTest.main(EmployeeTest.java:12)
    Caused by: Exception [EclipseLink-4021] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.DatabaseException
    Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null].  Verify that you have set the expected driver class and URL.  Check your login, persistence.xml or sessions.xml resource.  The jdbc.driver property should be set to a class that is compatible with your database platform
    	at org.eclipse.persistence.exceptions.DatabaseException.unableToAcquireConnectionFromDriverException(DatabaseException.java:375)
    	at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:90)
    	at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:583)
    	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:227)
    	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:255)
    	... 4 more
    J'y comprend rien du tout

  6. #6
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 2 938
    Par défaut
    Il ne voit rien dans ton persistence.xml, il ne chope aucune des valeurs de ta datasource, tu le vois bien dans tes traces d'erreur.

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

Discussions similaires

  1. Réponses: 5
    Dernier message: 24/05/2011, 10h27
  2. Réponses: 4
    Dernier message: 12/04/2009, 19h53
  3. Réponses: 1
    Dernier message: 09/04/2009, 21h42
  4. [Toplink] No Persistence provider for EntityManager
    Par seb974 dans le forum Persistance des données
    Réponses: 1
    Dernier message: 21/03/2009, 20h02
  5. No Persistence provider for EntityManager
    Par DrumCode dans le forum JPA
    Réponses: 6
    Dernier message: 12/08/2008, 19h59

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