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é:
le fichier de persistence:
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)
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 <?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>
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(); } }
Partager