Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Bonjour,
J'essaye de générer du DDL avec ShemaExport en le lançant avec la tache Ant ShemaExportTask de HibernateTool. La tache se lance, lit le fichier de configuration et elle échoue en tentant de parser le premier fichier de mapping.
Message d'erreur:
Schema text failed: Could not parse mapping document
Le hibernate.cfg.xml fait référence à 2 fichiers de mapping, si j'inverse leur ordre dans Le hibernate.cfg.xml l'erreur est exactement la même mais pour l'autre fichier. SchemaExport échoue donc sur le premier fichier de mapping rencontré.
J'ai une console configuration définit avec le pluggin eclipse Hibernate Tools 3.2 beta9a, basée sur les mêmes fichiers de mapping qui se comporte normalement.
Je ne comprends pas ce qui se passe.
Hibernate version:
3.2.2
Hibernate Tools 3.2 beta9a,
Mapping documents:
hibernate.cfg.xml:
<?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>
<property name="hibernate.connection.driver_class">
org.hsqldb.jdbcDriver
</property>
<property name="hibernate.connection.url">
jdbc:hsqldb:hsql://localhost/db1
</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.default_schema">PUBLIC</property>
<property name="hibernate.dialect">
org.hibernate.dialect.HSQLDialect
</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<mapping resource="sca/hibernate1/entities/Person.hbm.xml" />
<mapping resource="sca/hibernate1/entities/Event.hbm.xml" />
</session-factory>
</hibernate-configuration>
Person.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="sca.hibernate1.entities">
<class name="Person" table="H_PERSON" >
<id name="id" column="ID">
<generator class="increment" />
</id>
<property name="name" column="LASTNAME"/>
<set name="events" table="PERSON_EVENT">
<key column="PERSON_ID"/>
<many-to-many class="Event" column="EVENT_ID"/>
</set>
</class>
</hibernate-mapping>
Event.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="sca.hibernate1.entities">
<class name="Event" table="EVENTS">
<id name="id" column="ID">
<generator class="increment" />
</id>
<property name="title"/>
<property name="date" type="timestamp" column="EVENT_DATE"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Ant buil file:
<project name="build mv" basedir=".">
<property name="src" location="src" />
<property name="bin" location="bin" />
<property name="lib.home" location="D:/lib/" />
<path id="classpath">
<fileset dir="${lib.home}\hibernate-3.2\" includes="**/*.jar" />
<pathelement path="${src}" />
</path>
<target name="schemaExport">
<taskdef name="schemaExport" classname="org.hibernate.tool.hbm2ddl.SchemaExportTask" classpathref="classpath" />
<schemaExport output="schema-export.sql" config="${src}\hibernate.cfg.xml" text="yes" quiet="no" drop="no">
<fileset dir="${src}">
<include name="**/*.hbm.xml,**/*.cfg.xml" />
</fileset>
</schemaExport>
</target>
</project>
Full stack trace of any exception that occurs:
console stack:
Buildfile: D:\Callisto\workspaces\default\hibernate1\build-mv.xml
schemaExport:
[schemaExport] 17:00:50,484 INFO Environment:509 - Hibernate 3.2.2
[schemaExport] 17:00:50,500 INFO Environment:542 - hibernate.properties not found
[schemaExport] 17:00:50,500 INFO Environment:676 - Bytecode provider name : cglib
[schemaExport] 17:00:50,500 INFO Environment:593 - using JDK 1.4 java.sql.Timestamp handling
[schemaExport] 17:00:50,562 INFO Configuration:1460 - configuring from file: hibernate.cfg.xml
[schemaExport] 17:00:50,609 DEBUG DTDEntityResolver:38 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd]
[schemaExport] 17:00:50,625 DEBUG DTDEntityResolver:40 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
[schemaExport] 17:00:50,625 DEBUG DTDEntityResolver:50 - located [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd] in classpath
[schemaExport] 17:00:50,671 DEBUG Configuration:1387 - hibernate.connection.driver_class=org.hsqldb.jdbcDriver
[schemaExport] 17:00:50,671 DEBUG Configuration:1387 - hibernate.connection.url=jdbc:hsqldb:hsql://localhost/db1
[schemaExport] 17:00:50,671 DEBUG Configuration:1387 - hibernate.connection.username=sa
[schemaExport] 17:00:50,671 DEBUG Configuration:1387 - hibernate.default_schema=PUBLIC
[schemaExport] 17:00:50,671 DEBUG Configuration:1387 - hibernate.dialect=org.hibernate.dialect.HSQLDialect
[schemaExport] 17:00:50,671 DEBUG Configuration:1387 - current_session_context_class=thread
[schemaExport] 17:00:50,671 DEBUG Configuration:1387 - show_sql=true
[schemaExport] 17:00:50,671 DEBUG Configuration:1387 - connection.pool_size=1
[schemaExport] 17:00:50,671 DEBUG Configuration:1586 - null<-org.dom4j.tree.DefaultAttribute@87c268 [Attribute: name resource value "sca/hibernate1/entities/Person.hbm.xml"]
[schemaExport] 17:00:50,671 INFO Configuration:553 - Reading mappings from resource : sca/hibernate1/entities/Person.hbm.xml
[schemaExport] 17:00:50,687 DEBUG DTDEntityResolver:38 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
[schemaExport] 17:00:50,687 DEBUG DTDEntityResolver:40 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
[schemaExport] 17:00:50,687 DEBUG DTDEntityResolver:50 - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
[schemaExport] 17:00:50,781 INFO HbmBinder:300 - Mapping class: sca.hibernate1.entities.Person -> H_PERSON
BUILD FAILED
D:\Callisto\workspaces\default\hibernate1\build-mv.xml:15: Schema text failed: Could not parse mapping document from resource sca/hibernate1/entities/Person.hbm.xml
Total time: 1 second
Name and version of the database you are using:
hsqldb 1.8.0
Merci d'avance.