Bonjour à tous.
Je viens à vous suite à ma perte de cheveux, me les tirant énormément... ; )
J'ai un une erreur de ce type :
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 !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpaTerm
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 :
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 <?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>
Mon fichier Spring associant la persistance et la base
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>
spring-persistence.xml
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
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>
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 <?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>
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
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; } }
A ce niveau de l'appel j'ai donc cette erreur
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
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 ; )
Partager