Bonjour ,

J'utilise la première fois spring et je me trouve avec cette erreur dont je connais pas la cause.

NB: j'utilise une classe de test que j'exécute avec Junit
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
50
51
52
53
54
55
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [application-context.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: @OneToOne or @ManyToOne on model.Client.risque references an unknown entity: model.Risque
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1488)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:608)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
	at TestJunit.ServiceTest.setUpBeforeClass(ServiceTest.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
	at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
	at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
	at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on model.Client.risque references an unknown entity: model.Risque
	at org.hibernate.cfg.FkSecondPass.doSecondPass(FkSecondPass.java:56)
	at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:428)
	at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
	at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1121)
	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:720)
	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1547)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1485)
	... 26 more
 
java.lang.NullPointerException
	at TestJunit.ServiceTest.tearDownAfterClass(ServiceTest.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
	at org.junit.internal.runners.BeforeAndAfterRunner.runAfters(BeforeAndAfterRunner.java:65)
	at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:37)
	at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Voici la classe Risque.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package model;
 
// Generated 23 mars 2014 13:04:26 by Hibernate Tools 3.4.0.CR1
 
import java.util.HashSet;
import java.util.Set;
 
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
 
/**
 * Risque generated by hbm2java
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "risque", catalog = "commercialbase")
public class Risque implements java.io.Serializable {
 
	private int idrisque;
	private String nomRisque;
	private Set<Fournisseur> fournisseurs = new HashSet<Fournisseur>(0);
	private Set<Client> clients = new HashSet<Client>(0);
 
	public Risque() {
	}
 
	public Risque(int idrisque) {
		this.idrisque = idrisque;
	}
 
	public Risque(int idrisque, String nomRisque, Set<Fournisseur> fournisseurs, Set<Client> clients) {
		this.idrisque = idrisque;
		this.nomRisque = nomRisque;
		this.fournisseurs = fournisseurs;
		this.clients = clients;
	}
 
	@Id
	@Column(name = "idrisque", unique = true, nullable = false)
	public int getIdrisque() {
		return this.idrisque;
	}
 
	public void setIdrisque(int idrisque) {
		this.idrisque = idrisque;
	}
 
	@Column(name = "nom_risque", length = 45)
	public String getNomRisque() {
		return this.nomRisque;
	}
 
	public void setNomRisque(String nomRisque) {
		this.nomRisque = nomRisque;
	}
 
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "risque")
	public Set<Fournisseur> getFournisseurs() {
		return this.fournisseurs;
	}
 
	public void setFournisseurs(Set<Fournisseur> fournisseurs) {
		this.fournisseurs = fournisseurs;
	}
 
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "risque")
	public Set<Client> getClients() {
		return this.clients;
	}
 
	public void setClients(Set<Client> clients) {
		this.clients = clients;
	}
 
}
Voici la classe de test
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package TestJunit;
 
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import model.Client;
 
//import java.util.Iterator;
import java.util.List;
 
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
 
//import services.IEnseignantService;
//import services.IEtudiantService;
import services.*;
 
public class ServiceTest {
 
	private static ClassPathXmlApplicationContext context;
   // private  static IEtudiantService etudiantservice;
    //private  static IEnseignantService enseignantservice;
	private  static IClientDao clientDAO;
 
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		context = new ClassPathXmlApplicationContext("/application-context.xml");
	/*
		etudiantservice= (IEtudiantService) context.getBean("etudiantService");
		enseignantservice= (IEnseignantService) context.getBean("enseignantService");
	*/
		clientDAO =(IClientDao)context.getBean("clientDAO"); }
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		context.close();
	}
 
@Test
	public void testFindAll() {
 
	List<Client> maliste=clientDAO.findAll();
	assertNotNull(maliste);
	assertTrue(maliste.size() > 0);
	for (int i=0;i<maliste.size();i++) {
		System.out.println(maliste.get(i));
 
	}
 
	}
/*
//@Test
public void testInsertEnseign() {
 
	Enseignant ens = new Enseignant();
	ens.setNomEnseignant("Islam");
	enseignantservice.enregistrer(ens);
}
 
/*
//@Test
public void testFindAll2() {
 
List<Domaine> maliste=domaineservice.lister();
assertNotNull(maliste);
assertTrue(maliste.size() > 0);
 
for (Domaine d : maliste) {
 
System.out.println(d.getDomaine()); } 
 
 
}
 
 
//@Test
public void testFindAll3() {
 
List<Stage> maliste=stageservice.lister();
assertNotNull(maliste);
assertTrue(maliste.size() > 0);
 
for (Stage d : maliste) {
 
System.out.println(d.getSujet()); } 
 
 
}
 
//@Test
public void testFindAll4() {
 
List<Encadreur> maliste=encadreurservice.lister();
assertNotNull(maliste);
assertTrue(maliste.size() > 0);
 
for (Encadreur d : maliste) {
 
System.out.println(d.getNom()); } 
 
 
}
 
@Test
public void testaffectation() {
 
	StageAffectation aff=new StageAffectation();
    StageAffectationId id=new StageAffectationId(974424, 60);
    aff.setId(id);
    affservice.enregistrer(aff);
 
}*/
 
}
Voici le fichier applicationContext.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:c="http://www.springframework.org/schema/c"
	xmlns:cache="http://www.springframework.org/schema/cache"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:faces="http://www.springframework.org/schema/faces"
	xmlns:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:jms="http://www.springframework.org/schema/jms"
	xmlns:lang="http://www.springframework.org/schema/lang"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:security="http://www.springframework.org/schema/security"
	xmlns:task="http://www.springframework.org/schema/task"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:util="http://www.springframework.org/schema/util"
	xmlns:webflow-config="http://www.springframework.org/schema/webflow-config"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
		http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
		http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces-2.2.xsd
		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
		http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-2.5.xsd
		http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.2.xsd
		http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
		http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">
 
 
 
 
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<property name="url" value="jdbc:mysql://localhost:3306/commercialbase" />
		<property name="username" value="root" />
		<property name="password" value="syrine" />
	</bean>
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="annotatedClasses">
			<list>
 
 
				<value>model.Client</value>
 
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
			</props>
		</property>
	</bean>
 
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
 
 
 
	<tx:annotation-driven transaction-manager="transactionManager" />
 
	<context:annotation-config />
 
 
	<context:component-scan base-package="model" />
	<context:component-scan base-package="services" />
	<context:component-scan base-package="web" />
	<context:component-scan base-package="TestJunit" />
</beans>
Et dernièrement voilà le fichier de configuration hibernate
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
		"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
		"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory name="sessionFactory">
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.password">syrine</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/commercialbase</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
    </session-factory>
</hibernate-configuration>
veulliez m'aider SVP