Bonjour ,

je veux intégrer Sping orm dans mon application pour s’occuper de la couchepersistance , mais j’ai rencontré une exception qui me bloque jusqu’à présent .Si quelqu’un à une solution ou voir même des pistes je suis preneur et vraiment j’en serais reconnaissant.

L’exception est la suivante :
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
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [beans-hibernate.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Unable to read XML
 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
 
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
 
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
 
at test.Main.main(Main.java:18)
 
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
 
at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:101)
 
at org.hibernate.cfg.Configuration.add(Configuration.java:513)
 
at org.hibernate.cfg.Configuration.add(Configuration.java:509)
 
at org.hibernate.cfg.Configuration.add(Configuration.java:689)
 
at org.hibernate.cfg.Configuration.addResource(Configuration.java:774)
 
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2317)
 
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2283)
 
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2263)
 
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2216)
 
at org.hibernate.cfg.Configuration.configure(Configuration.java:2167)
 
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:642)
 
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
 
... 12 more
 
Caused by: org.dom4j.DocumentException: Error on line 2 of document: The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed.
 
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
 
at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:75)
 
... 25 more
La classe Main :
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
public class Main
{
 
publicstaticvoid main(String[] args)
 
{
 
ApplicationContext context =
 
new ClassPathXmlApplicationContext("beans-hibernate.xml");
 
AttributDAOImpl attributDAOImpl = (AttributDAOImpl) context.getBean("AttributDAOImpl");
 
List<Attribut> attributs= attributDAOImpl.findAll();
 
System.out.println(attributs);
 
}
 
}
Le document beans-hibernate.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
<?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="sessionFactory"
 
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
 
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
 
</bean>
 
<bean id="AttributDAOImpl" class="util.HibernateUtil">
 
<property name="sessionFactory" ref="sessionFactory" />
 
</bean>
 
</beans>
Le document hibernate.cfg.xml (que je l’ai ajouté dans la class Path du projet ):[/SIZE][/U][/B]
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
<?xml version='1.0' encoding='utf-8'?>
 
<!DOCTYPE hibernate-configuration
 
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
 
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 
<hibernate-configuration>
 
<session-factory>
 
<!-- local connection properties -->
 
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/test</property>
 
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
 
<property name="hibernate.connection.username">usermarie</property>
 
<property name="hibernate.connection.password"></property>
 
<!-- property name="hibernate.connection.pool_size"></property -->
 
<!-- dialect for DB2 -->
 
<property name="dialect">net.sf.hibernate.dialect.DB2Dialect</property>
 
<property name="hibernate.show_sql">false</property>
 
<property name="hibernate.use_outer_join">true</property>
 
<property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
 
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
 
<!-- pour le mapping via les fichier xml -->
 
<mapping resource="model/attribut.hbm.xml" />
 
<!-- pour le mapping via les annotations -->
 
<!--Pour les annotations JPA. -->
 
<!--
 
<mapping class="nom complet de la classe" />
 
-->
 
</session-factory>
 
</hibernate-configuration>
Merci d’avance

-
Edité par zrjava il y a moins de 5s