Bonjour,

je suis le tuto de S. TAHE, "JPA, persistance Java par la pratique", et après un exemple avec Hibernate, je dois utiliser toplink pour constater les apports de JPA.
après avoir téléchargé toplink sur le site d'Oracle, j'ai créé dans eclipse une librairie utilisateur avec TOUS les JARS du fichier, apparemment tout va bien, j'ai incorporé cette librairie dans le projet et j'ai lancé le programme dont voici 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
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("jpa");
		// 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é ...");
	}
}
l'erreur est:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpa
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
at tests.InitDB.main(InitDB.java:19)
l'erreur se situe au niveau de la création de l'entityManager.

voici le fichier persistence.xml, si besoin 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
33
34
 
<?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">
		<!--  provider -->
		<provider>oracle.toplink.essentials.PersistenceProvider</provider>
		<!-- classes persistantes -->
		<class>entites.Personne</class>
		<!-- propriétés de l'unité de persistance -->
		<properties>
			<!-- connexion JDBC -->
			<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver" />
			<property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/jpa" />
			<property name="toplink.jdbc.user" value="jpa" />
			<property name="toplink.jdbc.password" value="jpa" />
			<property name="toplink.jdbc.read-connections.max" value="3" />
			<property name="toplink.jdbc.read-connections.min" value="1" />
			<property name="toplink.jdbc.write-connections.max" value="5" />
			<property name="toplink.jdbc.write-connections.min" value="2" />
			<!-- SGBD -->
			<property name="toplink.target-database" value="MySQL4" />
			<!--  serveur d'application -->
			<property name="toplink.target-server" value="None" />
			<!--  génération schéma -->
			<property name="toplink.ddl-generation" value="drop-and-create-tables" />
			<property name="toplink.application-location" value="ddl/mysql5" />
			<property name="toplink.create-ddl-jdbc-file-name" value="create.sql" />
			<property name="toplink.drop-ddl-jdbc-file-name" value="drop.sql" />
			<property name="toplink.ddl-generation.output-mode" value="both" />
			<!-- logs -->
			<property name="toplink.logging.level" value="OFF" />
		</properties>
	</persistence-unit>
</persistence>
le soul pb que j'ai vu est l'utilisation dans persistence.xml de mysql4 alors que j'ai mysql5, mais le tuto fait pareil (et ça marche pour lui...).

merci,

lolveley.