bonjour,
je débute avec jpa et je ne suis pas arrivé a générer mon entité en exécutant la classe principale main
je vous montre l'entité
et la classe principale
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 import java.io.Serializable; import java.lang.Long; import java.lang.String; import javax.persistence.*; public class Formation implements Serializable { private Long id; private String theme; private static final long serialVersionUID = 1L; public Formation() { super(); } public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } public String getTheme() { return this.theme; } public void setTheme(String theme) { this.theme = theme; } }
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 import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; import javax.persistence.Persistence; public class DemoJpa { public static void main(String[] args) { EntityManagerFactory emf=Persistence.createEntityManagerFactory("demojpa"); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); tx.begin(); Formation formation= new Formation(); tx.commit(); em.close(); emf.close(); } }une fois lancer run une fenêtre message d'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 <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" 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"> <persistence-unit name="demojpa"> <properties> <property name="hibernate.archive.autodetection" value="class" /> <!-- <property name="hibernate.show_sql" value="true" /> --> <property name="hibernate.format_sql" value="true" /> <!-- Configuration de la BDD --> <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver" /> <property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:FIN" /> <property name="hibernate.connection.username" value="DO" /> <property name="hibernate.connection.password" value="DO" /> <!-- Spécifie le 'dialecte' SQL utilisé pour communiquer avec la BDD --> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> <!-- Indique a Hibernate de (re-)créer la BDD au lancement de l'application --> <property name="hibernate.hbm2ddl.auto" value="create" /> </properties> </persistence-unit> </persistence>
merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named demojpa at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) at DemoJpa.main(DemoJpa.java:10)
Partager