Bonjour,

J'ai utilisé ce tutorial pour une creation d'un projet JSF, Hibernate, Spring en ajoutant les annotations.

J'ai une classe Pays comme cela :

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
@Entity
@Table(name = "pays", catalog = "mybd", uniqueConstraints = {
		@UniqueConstraint(columnNames = "libelle")})
public class Pays {
 
	public int idPays;
	public String libelle;
 
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id_pays", unique = true, nullable = false)
	public int getIdPays() {
		return idPays;
	}
 
	public void setIdPays(int idPays) {
		this.idPays = idPays;
	}
 
	@Column(name = "libelle", unique = true, nullable = false, length = 255)
	public String getLibelle() {
		return libelle;
	}
 
	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}
 
}
et dans mon PaysDaoImpl j'ai cela :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
public class PaysDaoImpl extends HibernateDaoSupport implements PaysDao{
 
	@SuppressWarnings("unchecked")
	@Override
	public List<Pays> findAllPays() {
		Session session = getSessionFactory().openSession();
		List<Pays> list = session.createCriteria(Pays.class).list();
		session.close();
		return list;
	}
}
La liste retournée est vide.

Les autres fichiers de configurations sont les suivants :

db.properties :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybd
jdbc.username=root
jdbc.password=root
PaysBean.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
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
   	<bean id="paysBo" 
         class="com.bo.impl.PaysBoImpl" >
   		<property name="paysDao" ref="paysDao" />
   	</bean>
 
   	<bean id="paysDao" 
         class="com.dao.impl.PaysDaoImpl" >
   		<property name="sessionFactory" ref="sessionFactory" />
   	</bean>
 
</beans>
le datasource.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
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
 <bean 
   class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="location">
		<value>WEB-INF/classes/config/database/db.properties</value>
   </property>
</bean>
 
  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
	<property name="driverClassName" value="${jdbc.driverClassName}" />
	<property name="url" value="${jdbc.url}" />
	<property name="username" value="${jdbc.username}" />
	<property name="password" value="${jdbc.password}" />
  </bean>
 
</beans>
et le HibernateSessionFactory.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
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
	<!-- Hibernate session factory -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
 
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
 
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>
 
		<!-- <property name="mappingResources">
			<list>
				<value>com/faycal/customer/hibernate/Customer.hbm.xml</value>
			</list>
		</property> -->
 
		<property name="mappingLocations">
			<list>
				<value>classpath:com/hibernate/*.hbm.xml</value>
			</list>
		</property>
 
	</bean>
</beans>
et 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
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-2.5.xsd">
 
	<!-- Database Configuration -->
	<import resource="classes/config/spring/beans/DataSource.xml"/>
	<import resource="classes/config/spring/beans/HibernateSessionFactory.xml"/>
 
	<!-- Beans Declaration -->
	 	<import resource="classes/com/spring/PaysBean.xml"/>
 
</beans>

Je trouve pas ce qui manque pour avoir les données de la base, merci pour votre aide