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 !


Sujet :

JPA Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 85
    Par défaut No Persistence Provider !
    Bonjour à tous.

    Je viens à vous suite à ma perte de cheveux, me les tirant énormément... ; )

    J'ai un une erreur de ce type :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpaTerm
    J'ai vu grand nombre de site spécifiant telle ou telle solution, mais tout me semble correct ici et n'en trouve la fin !

    Je travail sous Eclipse Helios, tomcat, Spring3, Jpa, Hibernate3

    J'ai configuré mon fichier persistence.xml présent dans "META-INF/persistence.xml" (Il est bien présent dans mon Classpath)

    Classpath :
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
    	<classpathentry kind="src" path="src"/>
    	<classpathentry kind="src" path="WebContent/META-INF"/>
    	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM Contents (MacOS X Default)">
    		<attributes>
    			<attribute name="owner.project.facets" value="java"/>
    		</attributes>
    	</classpathentry>
    	<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0">
    		<attributes>
    			<attribute name="owner.project.facets" value="jst.web"/>
    		</attributes>
    	</classpathentry>
    	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
    	<classpathentry kind="output" path="WebContent/WEB-INF/classes"/>
    </classpath>
    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
    <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_2_0.xsd" version="2.0">
    <persistence-unit name="jpaTerm" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.echange.model.Continent</class>
    <class>com.echange.model.Pays</class>
    <properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
    <property name="hibernate.hbm2ddl.auto" value="update"/>
    <property name="hibernate.show_sql" value="true" />
    <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
    <property name="use_sql_comments" value="false" />
    <property name="hibernate.query.substitutions" value="true" />
    <property name="hibernate.show_sql" value="true" />
    </properties>
    </persistence-unit>
    </persistence>
    Mon fichier Spring associant la persistance et la base
    spring-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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
     
    <?xml version="1.0" encoding="UTF-8"?> 
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" 
    xsi:schemaLocation=" 
       http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
       http://www.springframework.org/schema/aop 
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> 
       <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> 
       <tx:annotation-driven /> 
     
       <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
          <property name="dataSource" ref="dataSource" /> 
          <property name="persistenceXmlLocation" value="META-INF/persistence.xml"/>
          <property name="persistenceUnitName" value="jpaTerm" /> 
          <property name="jpaVendorAdapter"> 
             <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 
                <property name="database" value="POSTGRESQL" /> 
                <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" /> 
             </bean> 
          </property> 
       </bean> 
     
       <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> 
     
       <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
          <property name="driverClassName" value="org.postgresql.Driver" /> 
          <property name="url" value="jdbc:postgresql://localhost:5674/superbase" /> 
           <property name="username" value="superman" /> 
           <property name="password" value="superCode" /> 
     
       </bean> 
     
       <bean id="hibernateDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" /> 
     
       <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
          <property name="entityManagerFactory" ref="entityManagerFactory" /> 
          <property name="dataSource" ref="dataSource" /> 
          <property name="jpaDialect" ref="hibernateDialect" /> 
          <qualifier value="echangeResidence"/> 
       </bean> 
     
    	<!-- traduction des exceptions -->
    	<!--  <bean class="orgspringframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
    	-->
     
    </beans>
    Mon applicationContext.xml de spring

    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
     
    <?xml version="1.0" encoding="UTF-8"?> 
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    ">
     
       <import resource="spring-persistence.xml" /> 
     
      <!-- mon fichier de bean -->
       <import resource="business.xml" /> 
     
        <!-- Ceci est mon entrée de service appelé à distance par mon client  -->
       <bean id="stateBean" class="com.bad.Place"/>	   
     
    </beans>
    Ma classe qui créé ma FactoryEntityManager à l'appel de init()

    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
    package com.bad.bussiness;
    
    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.Persistence;
    import javax.persistence.PersistenceContext;
    import javax.persistence.PersistenceUnit;
    import javax.persistence.PersistenceUnit;
    import javax.persistence.PersistenceContext;
    
    public class FactoryEntityManager {
    	
    	/*@PersistenceUnit(unitName="jpaTerm")*/
    	private EntityManagerFactory factory;
    
    	/*@PersistenceContext(unitName="jpaTerm")*/
    	private EntityManager entityManager;
    
    		public void FactoryEntityManager()
    		{
    			 System.out.println("EntityManagerFactory");
    	
    		}
    		
    	   public void init() {
    		   System.out.println("EntityManagerFactory init()");
    		 try{
    			 factory = Persistence.createEntityManagerFactory("jpaTerm");
    			 System.out.println("yep passé");
    		   	}catch(Exception e)
    		   	{
    		   		System.out.println("pas bon "+e);
    		   	}
    	   	}
    
    	   public void close() {
    	      if (factory != null) {
    	         factory.close();
    	      }
    	   }
    	   
    	   public EntityManagerFactory getFactoryManager()
    	   {
    		   return factory;
    	   }
    	   
    	   public EntityManager getEntityManager()
    	   {
    		   return entityManager;
    	   }
    
    }
    Mes librairies :

    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
     
    antlr-2.7.6.jar
    c3p0-0.9.1.jar
    cfgatewayadapter.jar
    cglib-2.2.jar
    com.springsource.org.aopalliance-1.0.0.jar
    commons-codec-1.3.jar
    commons-collections-3.1.jar
    commons-httpclient-3.0.1.jar
    commons-logging.jar
    dom4j-1.6.1.jar
    eclipselink-2.0.0.jar
    ehcache-1.5.0.jar
    flex-messaging-common.jar
    flex-messaging-core.jar
    flex-messaging-opt.jar
    flex-messaging-proxy.jar
    flex-messaging-remoting.jar
    flex-rds-server.jar
    hibernate-jpa-2.0-api-1.0.0.Final.jar
    hibernate3.jar
    hsqldb-1_8_0_10.jar
    javassist-3.12.0.GA.jar
    javax.jar
    javax.persistence-2.0.0.jar
    javax.persistence.jar
    jta-1.1.jar
    org.springframework.aop-3.1.0.M1.jar
    org.springframework.asm-3.1.0.M1.jar
    org.springframework.aspects-3.1.0.M1.jar
    org.springframework.beans-3.1.0.M1.jar
    org.springframework.context-3.1.0.M1.jar
    org.springframework.context.support-3.1.0.M1.jar
    org.springframework.core-3.1.0.M1 - copie.jar
    org.springframework.expression-3.1.0.M1.jar
    org.springframework.instrument-3.1.0.M1.jar
    org.springframework.jdbc-3.1.0.M1.jar
    org.springframework.orm-3.1.0.M1.jar
    org.springframework.transaction-3.1.0.M1.jar
    org.springframework.web-3.1.0.M1.jar
    postgresql-9.0-801.jdbc3.jar
    slf4j-api-1.6.1.jar
    spring-security-config-3.1.0.RC1.jar
    spring-security-core-3.1.0.RC1.jar
    spring-security-openid-3.1.0.RC1.jar
    spring-security-taglibs-3.1.0.RC1.jar
    spring-security-web-3.1.0.RC1.jar
    xalan.jar
    A ce niveau de l'appel j'ai donc cette erreur

    javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpaTerm

    J'ai essayé l'annotation : @PersistenceUnit(unitName="jpaTerm") mais rien ne se créé, j'ai un 'null' sur "factory";

    Persitence.xml est bien trouvé, sinon j'aurai eus une erreur du style "FileNotFound" persistence.xml blabla

    Par ailleurs, mes classes Entity "pays" et "continent" se sont bien créé au lancement du serveur.
    INFO: Building JPA container EntityManagerFactory for persistence unit 'jpaTerm'
    Et je les trouvent en base.

    Je suis ouïe à toute suggestions : D !!

    Merci de votre intérêt ; )

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 85
    Par défaut
    J'ai résolu le problème :

    Cela ne répond pas à ma question qui est pourquoi :

    factory = Persistence.createEntityManagerFactory("jpaTerm");

    Me stipule une erreur de provider

    Mais, je suis passé par une autre méthode, d'injection de l'entityManager.

    Tout d'abord :

    Initialiser les beans à l'appel distant :
    applicationContext :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    <bean id="stateBean" class="com.dispatch.DispatchService">	
      		 <property name="springBeansAcces" ref="springBeansAcces"/>
       </bean>
    Dans la classe SpringBeansAcces :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     
    	private FactoryEntityManager factoryEntityManager;
     
    	public void setFactoryEntityManager(FactoryEntityManager factoryEntityManager) {
    		System.out.println("SpringBeansAcces setFactoryEntityManager");
    		this.factoryEntityManager = factoryEntityManager;
    	}
    Dans la classe FactoryEntityManager

    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
     
    @PersistenceUnit
    	private EntityManagerFactory entityManagerFactory;
     
     
    	   public EntityManagerFactory getEntityManagerFactory()
    	   {
    		   return entityManagerFactory;
    	   }
     
    	   public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) 
     
    	   {
    		   System.out.println("EntityManagerFactory setEntityManagerFactory()");
    		   this.entityManagerFactory = entityManagerFactory;
    	   }
    business.xml

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
       <bean id="factoryEntityManager" class="com.bad.bussiness.FactoryEntityManager"/>
     
       <bean id="springBeansAcces" class="com.bad.bussiness.SpringBeansAcces">
            <property name="factoryEntityManager" ref="factoryEntityManager"/>
       </bean>
    SpringBeans et donc généré via l'appel distant "stateBean" qui créé à son tour factoryEntityManager qui a à son sein le setter entityManagerFactory (de spring-persistence.xml).

    Si je ne me trompe :

    ce bean :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    est injecté dans le setter de la classe FactoryEntityManager, d'après les manipulations diverses de test que j'eus fait.

Discussions similaires

  1. Réponses: 5
    Dernier message: 24/05/2011, 10h27
  2. No Persistence provider for EntityManager
    Par DrumCode dans le forum JPA
    Réponses: 6
    Dernier message: 12/08/2008, 19h59
  3. Réponses: 4
    Dernier message: 01/12/2007, 22h22
  4. [EJB 3.0] Persistence provider
    Par pmartin8 dans le forum JPA
    Réponses: 8
    Dernier message: 23/04/2007, 16h26
  5. Réponses: 2
    Dernier message: 08/03/2007, 09h44

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