Bonjour,
Débutant en java, j'ai du mal à comprendre pourquoi ma classe de test me renvoi l'erreur en titre. J'ai développé un programme de calcul de salaire simplifié (exercice proposé par Serge Tahé). La version complète (Spring, JPA, Hibernate et IHM Swing) fonctionne sans problème. L'erreur survient à l'exécution d'une classe de test permettant de visualiser le contenu de ma base.
Je ne comprend pas comment le programme global fonctionne et pas la classe de test. Manque-t-il quelque chose dans ma config ?
Classe de test
spring-config.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
20
21
22
23
24
25 public class InitDB { // couche service private static IMetier metier; // constructeur public static void main(String[] args) throws ParseException { // configuration de l'application ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-config.xml"); // couche service metier = (IMetier) ctx.getBean("metier"); // on vérifie visuellement getAllEmployes(); } // affichage contenu table private static void getAllEmployes() { System.out.format("[employes]%n"); for (Employe e : metier.getAllEmploye()) { System.out.println(e); } System.out.println("\n"); } }
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
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 <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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <!-- couches applicatives --> <bean id="cotisationDao" class="dao.CotisationDao" /> <bean id="employeDao" class="dao.EmployeDao" /> <bean id="indemniteDao" class="dao.IndemniteDao" /> <bean id="metier" class="metier.Metier"> <property name="cotisationDao" ref="cotisationDao" /> <property name="employeDao" ref="employeDao" /> <property name="indemniteDao" ref="indemniteDao" /> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true" /> <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" /> <property name="generateDdl" value="true" /> </bean> </property> <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" /> </property> </bean> <!-- la source de donnéees DBCP --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost/dbpam" /> <property name="username" value="root" /> <property name="password" value="" /> </bean> <!-- le gestionnaire de transactions --> <tx:annotation-driven transaction-manager="txManager" /> <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <!-- traduction des exceptions --> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> <!-- persistence --> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> </beans>
Merci d'avance pour vos réponse.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 <persistence version="1.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_1_0.xsd"> <persistence-unit name="jpa" transaction-type="RESOURCE_LOCAL"/> </persistence>
Partager