Ajout de la balise [Code]. Merci d'y penser.
Merci ,
mais j'ai pas aucune modification du fichier que vous avez demandé "commons-logging".si je doit faire une configuration je sais pas comment?
pour vous donné une idée sur le projet, j'ai un projet java,j'ai crée une classe Personne ("@Entity"), et j'ai un fichier persistence.xml décrit ci-dessus, et une clase InitDB.java,:
Code:
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é ...");
}
} |
sachant que le persistence-unit du nom jpa est définit dans le fichier persistence.xml
Merci d'avance,
Cordialement ,
Y.H