MappingNotFoundException pour l'initialisation de la session
Bonsoir.
Je débute avec Hibernate, j'ai réussi à faire fonctionner le tuto officiel, maintenant j'essaie de mapper un objet simple avec une table de ma BDD. C'est l'objet ProticProjet, il ne contient que 3 champs : l'id (int), le nom (String) et la description (String).
Le soucis que j'ai, comme beaucoup d'autres personnes d'après mes recherches vaines, c'est que quand je lance la requête pour que le mapping soit effectué, le fichier de mapping n'est pas trouvé :
Citation:
Initial SessionFactory creation failed.org.hibernate.MappingNotFoundException: resource: fr/inra/moulon/server/hibernate/ProticProject.hbm.xml not found
En fait, j'ai packagé mon application (utilisant Apache CXF) dans un .war que je lance avec le serveur standalone jetty-runner.jar. Je peux donc déployer mon application sans problème visible, mais si je lance une requête sur mon appli web, l'erreur ci-dessus apparaît.
J'ai vérifié que le fichier en question était bien présent dans le répertoire en question dans le fichier .war. J'ai testé également tous les chemins qui me sont venus à l'idée dans le mapping du fichier de configuration d'Hibernate.
Voici le stacktrace complet :
Voici le contenu du fichier hibernate.cfg.xml :
Code:
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
| <?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>
<!-- Database connection settings -->
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://db_host/db_name</property>
<property name="connection.username">login</property>
<property name="connection.password">pwsrd</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">2</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- Enable Hibernates current session context -->
<!-- <property name="current_session_context_class">org.hibernate.context.ManagedSessionContext</property> -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hibernate.hbm2ddl.auto">validate</property>
<!-- <property name="hbm2ddl.auto">validate</property>-->
<!-- <mapping resource="ProticProject.hbm.xml"/>-->
<!-- <mapping resource="/home/logini/Documents/proticWS/workspace/ProticPort/src/resources/ProticProject.hbm.xml"/>-->
<mapping resource="fr/inra/moulon/server/hibernate/ProticProject.hbm.xml"/>
</session-factory>
</hibernate-configuration> |
Voici le contenu du fichier de mapping ProticProject.hbm.xml :
Code:
1 2 3 4 5 6 7 8 9 10 11
| <hibernate-mapping package="main.java.fr.inra.moulon.server.hibernate">
<class name="ProticProject" table="protic_projects">
<id name="id" column="project_id">
<generator class="native"/>
</id>
<property name="name" column="project_name"/>
<property name="description" column="project_description"/>
</class>
</hibernate-mapping> |
Voici l'arborescence de mon répertoire source :
Code:
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
| src/
|-- main
| |-- java
| | `-- fr
| | `-- inra
| | `-- moulon
| | |-- Utils.java
| | `-- server
| | |-- CsvStreamer.java
| | |-- GetDataService.java
| | |-- JsonStreamer.java
| | |-- X2dbi.java
| | |-- hibernate
| | | |-- HibernateUtil.java
| | | |-- ProticProject.java
| | | `-- ProticProjectManager.java
| | `-- package-info.java
| `-- webapp
| |-- META-INF
| | `-- MANIFEST.MF
| |-- WEB-INF
| | |-- classes
| | | `-- proticport.properties
| | `-- web.xml
| `-- index.jsp
`-- resources
|-- ProticProject.hbm.xml
|-- fr
| `-- inra
| `-- moulon
| `-- server
| `-- hibernate
| `-- ProticProject.hbm.xml
|-- hibernate.cfg.xml
|-- proticport.properties
|-- query.xml
`-- query2.xml |
Voici l'arborescence de mon répertoire target :
Code:
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 115 116 117
| target/
|-- ProticPort
| |-- META-INF
| | `-- MANIFEST.MF
| |-- WEB-INF
| | |-- classes
| | | |-- main
| | | | `-- java
| | | | `-- fr
| | | | `-- inra
| | | | `-- moulon
| | | | |-- Utils.class
| | | | `-- server
| | | | |-- CsvStreamer.class
| | | | |-- GetDataService.class
| | | | |-- JsonStreamer.class
| | | | |-- X2dbi.class
| | | | |-- hibernate
| | | | | |-- HibernateUtil.class
| | | | | |-- ProticProject.class
| | | | | `-- ProticProjectManager.class
| | | | `-- package-info.class
| | | `-- proticport.properties
| | |-- lib
| | | |-- FastInfoset-1.2.3.jar
| | | |-- XmlSchema-1.4.5.jar
| | | |-- abdera-core-0.4.0-incubating.jar
| | | |-- abdera-extensions-json-0.4.0-incubating.jar
| | | |-- abdera-parser-0.4.0-incubating.jar
| | | |-- aopalliance-1.0.jar
| | | |-- commons-codec-1.2.jar
| | | |-- commons-httpclient-3.1.jar
| | | |-- commons-lang-2.4.jar
| | | |-- commons-logging-1.0.4.jar
| | | |-- cxf-api-2.2.1.jar
| | | |-- cxf-common-schemas-2.2.1.jar
| | | |-- cxf-common-utilities-2.2.1.jar
| | | |-- cxf-rt-bindings-soap-2.2.1.jar
| | | |-- cxf-rt-bindings-xml-2.2.1.jar
| | | |-- cxf-rt-core-2.2.1.jar
| | | |-- cxf-rt-databinding-aegis-2.2.1.jar
| | | |-- cxf-rt-databinding-jaxb-2.2.1.jar
| | | |-- cxf-rt-frontend-jaxrs-2.2.1.jar
| | | |-- cxf-rt-frontend-simple-2.2.1.jar
| | | |-- cxf-rt-transports-http-2.2.1.jar
| | | |-- cxf-tools-common-2.2.1.jar
| | | |-- dom4j-1.6.1.jar
| | | |-- geronimo-activation_1.1_spec-1.0.2.jar
| | | |-- geronimo-annotation_1.0_spec-1.1.1.jar
| | | |-- geronimo-javamail_1.4_spec-1.6.jar
| | | |-- geronimo-stax-api_1.0_spec-1.0.1.jar
| | | |-- hibernate3-3.3.2.GA.jar
| | | |-- jackson-asl-0.9.5.jar
| | | |-- javassist-3.8.0.GA.jar
| | | |-- jaxb-api-2.1.jar
| | | |-- jaxb-impl-2.1.9.jar
| | | |-- jettison-1.1.jar
| | | |-- jsr311-api-1.0.jar
| | | |-- neethi-2.0.4.jar
| | | |-- postgresql-8.3-603.jdbc3.jar
| | | |-- saaj-api-1.3.jar
| | | |-- shell-1.0.jar
| | | |-- slf4j-api-1.5.8.jar
| | | |-- slf4j-simple-1.5.8.jar
| | | |-- spring-beans-2.5.5.jar
| | | |-- spring-context-2.5.5.jar
| | | |-- spring-core-2.5.5.jar
| | | |-- spring-web-2.5.5.jar
| | | |-- wsdl4j-1.6.2.jar
| | | |-- wstx-asl-3.2.8.jar
| | | |-- xml-apis-1.0.b2.jar
| | | `-- xmlbeans-2.4.0.jar
| | `-- web.xml
| `-- index.jsp
|-- ProticPort.war
|-- classes
| |-- main
| | |-- java
| | | `-- fr
| | | `-- inra
| | | `-- moulon
| | | |-- Utils.class
| | | `-- server
| | | |-- CsvStreamer.class
| | | |-- GetDataService.class
| | | |-- JsonStreamer.class
| | | |-- X2dbi.class
| | | |-- hibernate
| | | | |-- HibernateUtil.class
| | | | |-- ProticProject.class
| | | | `-- ProticProjectManager.class
| | | `-- package-info.class
| | `-- webapp
| | |-- META-INF
| | | `-- MANIFEST.MF
| | |-- WEB-INF
| | | |-- classes
| | | | `-- proticport.properties
| | | `-- web.xml
| | `-- index.jsp
| `-- resources
| |-- ProticProject.hbm.xml
| |-- fr
| | `-- inra
| | `-- moulon
| | `-- server
| | `-- hibernate
| | `-- ProticProject.hbm.xml
| |-- hibernate.cfg.xml
| |-- proticport.properties
| |-- query.xml
| `-- query2.xml
|-- maven-archiver
| `-- pom.properties
`-- war
`-- work
`-- webapp-cache.xml |
Et cette arborescence, c'est cette de mon .war une fois dézippé :
Code:
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
| .
|-- META-INF
| |-- MANIFEST.MF
| `-- maven
| `-- fr.inra.moulon
| `-- ProticPort
| |-- pom.properties
| `-- pom.xml
|-- WEB-INF
| |-- classes
| | |-- main
| | | `-- java
| | | `-- fr
| | | `-- inra
| | | `-- moulon
| | | |-- Utils.class
| | | `-- server
| | | |-- CsvStreamer.class
| | | |-- GetDataService.class
| | | |-- JsonStreamer.class
| | | |-- X2dbi.class
| | | |-- hibernate
| | | | |-- HibernateUtil.class
| | | | |-- ProticProject.class
| | | | `-- ProticProjectManager.class
| | | `-- package-info.class
| | `-- proticport.properties
| |-- lib
| | |-- FastInfoset-1.2.3.jar
| | |-- XmlSchema-1.4.5.jar
| | |-- abdera-core-0.4.0-incubating.jar
| | |-- abdera-extensions-json-0.4.0-incubating.jar
| | |-- abdera-parser-0.4.0-incubating.jar
| | |-- aopalliance-1.0.jar
| | |-- commons-codec-1.2.jar
| | |-- commons-httpclient-3.1.jar
| | |-- commons-lang-2.4.jar
| | |-- commons-logging-1.0.4.jar
| | |-- cxf-api-2.2.1.jar
| | |-- cxf-common-schemas-2.2.1.jar
| | |-- cxf-common-utilities-2.2.1.jar
| | |-- cxf-rt-bindings-soap-2.2.1.jar
| | |-- cxf-rt-bindings-xml-2.2.1.jar
| | |-- cxf-rt-core-2.2.1.jar
| | |-- cxf-rt-databinding-aegis-2.2.1.jar
| | |-- cxf-rt-databinding-jaxb-2.2.1.jar
| | |-- cxf-rt-frontend-jaxrs-2.2.1.jar
| | |-- cxf-rt-frontend-simple-2.2.1.jar
| | |-- cxf-rt-transports-http-2.2.1.jar
| | |-- cxf-tools-common-2.2.1.jar
| | |-- dom4j-1.6.1.jar
| | |-- geronimo-activation_1.1_spec-1.0.2.jar
| | |-- geronimo-annotation_1.0_spec-1.1.1.jar
| | |-- geronimo-javamail_1.4_spec-1.6.jar
| | |-- geronimo-stax-api_1.0_spec-1.0.1.jar
| | |-- hibernate3-3.3.2.GA.jar
| | |-- jackson-asl-0.9.5.jar
| | |-- javassist-3.8.0.GA.jar
| | |-- jaxb-api-2.1.jar
| | |-- jaxb-impl-2.1.9.jar
| | |-- jettison-1.1.jar
| | |-- jsr311-api-1.0.jar
| | |-- neethi-2.0.4.jar
| | |-- postgresql-8.3-603.jdbc3.jar
| | |-- saaj-api-1.3.jar
| | |-- shell-1.0.jar
| | |-- slf4j-api-1.5.8.jar
| | |-- slf4j-simple-1.5.8.jar
| | |-- spring-beans-2.5.5.jar
| | |-- spring-context-2.5.5.jar
| | |-- spring-core-2.5.5.jar
| | |-- spring-web-2.5.5.jar
| | |-- wsdl4j-1.6.2.jar
| | |-- wstx-asl-3.2.8.jar
| | |-- xml-apis-1.0.b2.jar
| | `-- xmlbeans-2.4.0.jar
| `-- web.xml
`-- index.jsp |
La classe HibernateUtils, où est construite la session normalement est la suivante :
Code:
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
| package main.java.fr.inra.moulon.server.hibernate;
import java.io.File;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
File file = new File("/home/logini/Documents/proticWS/workspace/ProticPort/src/resources/hibernate.cfg.xml");
System.out.println("Le fichier hibernate.cfg.xml est ici : \n" + file.getAbsolutePath());
Configuration config = new Configuration();
config.configure(file);
sessionFactory = config.buildSessionFactory();
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.out.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
} |
Il y a certainement des erreurs dans la structuration de mon projet. Il est possible que l'erreur vienne de là.
Sauriez-vous pourquoi cette erreur persiste ? :?
Merci pour votre aide.