-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: schema-export: Schema text failed: Could not parse mapping..
PostPosted: Tue Jan 09, 2007 12:36 am 
Newbie

Joined: Tue Jan 09, 2007 12:28 am
Posts: 2
Hi,

I'm using Hibernate 3.2 and I'm trying to do an

Code:
ant schema-export


I was following the examples in Hibernate Quickly and this seemed to work on the simple Event example. Now, I'm trying to apply all this to my project. When I run it now, I get this error:

Quote:
BUILD FAILED
/Users/jon/jbproject/wp/build.xml:49: Schema text failed: Could not parse mapping document from file /Users/jon/jbproject/wp/src/java/com/snoopjonny/wp/Item.hbm.xml


I'm guessing this means my mapping file has a typo in it. Is there a way to get my detail on why it was unable to parse it?

Here is my mapping file:

Code:
<?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="com.snoopjonny.wp">
<class name="Item" table="item">
<id name="id" column="id" type="int">
<generator class="native" />
</id>
<property name="code" type="string" />
<property name="type" type="string" />
<property name="title" type="string" />
<property name="description" type="text" />
<property name="price" type="big_decimal" />
<property name="taxable" type="string" />
<property name="date_added" type="timestamp" />
</class>
</hibernate-mapping>


Thanks for your help.

-Jon


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 09, 2007 2:37 am 
Newbie

Joined: Tue Jan 09, 2007 12:28 am
Posts: 2
I did an:

Code:
ant -v schema-export


and got a message about duplicate class/entity. I tweaked my build.xml so it matched the successful one I used for Hibernate Quickly examples, and now there's no error. In fact, it says:

Quote:
jon$ ant schema-export
Buildfile: build.xml

init:
[mkdir] Created dir: /Users/jon/jbproject/wp/build/classes

compile:
[javac] Compiling 2 source files to /Users/jon/jbproject/wp/build/classes

schema-export:
[schemaexport] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
[schemaexport] log4j:WARN Please initialize the log4j system properly.

BUILD SUCCESSFUL
Total time: 3 seconds
MacbookPro:~/jbproject/wp jon$


but nothing is done in the database and nothing is written to schema-export.sql. I am really stumped because the practically identical setup in a parallel directory works just fine.

build.xml:
Code:
<?xml version="1.0"?>
<project name="build.xml" default="build">
  <property name="src.java.dir" location="src/java" />
  <property name="build.classes.dir" location="build/classes" />
  <property name="hibernate.version" value="3.2" />
  <property name="mysql.jdbc.version" value="5.0.4" />
  <property name="hibernate.lib.dir" location="/usr/local/hibernate-${hibernate.version}" />
  <property name="jdbc.driver.jar" location="/usr/local/mysql-connector-java-${mysql.jdbc.version}/mysql-connector-java-${mysql.jdbc.version}-bin.jar" />
  <property name="hibernate.tools.dir" location="${hibernate.lib.dir}/lib" />


  <import file="hibernate-build.xml" />

  <path id="project.classpath">
    <pathelement location="${build.classes.dir}" />
    <pathelement location="${jdbc.driver.jar}" />
    <path refid="hibernate.lib.path" />
    <pathelement location="${hibernate.tools.dir}" />
  </path>

  <path id="runtime.classpath">
    <path refid="project.classpath" />
    <path refid="hibernate.lib.path" />
    <pathelement location="${jdbc.driver.jar}" />
    <pathelement location="${src.java.dir}" />
  </path>

  <target name="clean">
    <delete dir="${build.classes.dir}" />
  </target>

  <target name="init">
    <mkdir dir="${build.classes.dir}" />
  </target>

  <target name="compile" depends="init" >
    <javac srcdir="${src.java.dir}" destdir="${build.classes.dir}">
      <classpath refid="hibernate.lib.path" /> 
    </javac>
  </target>

  <target name="build" depends="compile" >
  </target>

  <target name="schema-export" depends="compile" >
    <taskdef name="schemaexport" classname="org.hibernate.tool.hbm2ddl.SchemaExportTask">
      <classpath refid="runtime.classpath" />
    </taskdef>
    <schemaexport config="${src.java.dir}/hibernate.cfg.xml" output="schema-export.sql" />
  </target>

  <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="project.classpath" />
  <target name="codegen" description="Generate Java source from the O/R mapping files">
    <hibernatetool destdir="${src.java.dir}">
      <configuration>
        <fileset dir="${src.java.dir}">
          <include name="**/*.hbm.xml" />
        </fileset>
      </configuration>
      <hbm2java />
    </hibernatetool>
  </target>

</project>


hibernate-build.xml:
Code:
<?xml version="1.0"?>
<project name="hibernate-build.xml" default="build">
  <path id="hibernate.lib.path">
    <fileset dir="${hibernate.lib.dir}/lib">
      <include name="**/*.jar" />
    </fileset>
    <fileset dir="${hibernate.lib.dir}">
      <include name="hibernate3.jar" />
    </fileset>
  </path>
  <target name="default" />
</project>


hibernate.cfg.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
      <property name="connection.username">root</property>
      <property name="connection.password"></property>
      <property name="connection.url">
         jdbc:mysql://localhost/wp
      </property>
      <property name="connection.driver_class">
         com.mysql.jdbc.Driver
      </property>
      <property name="dialect">
        org.hibernate.dialect.MySQLDialect
      </property>
      <mapping resource="com/snoopjonny/wp/hibernate/Item.hbm.xml" />
    </session-factory>
</hibernate-configuration>


Item.hbm.xml:
Code:
<?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="com.snoopjonny.wp.hibernate">
  <class name="Item" table="item">
    <id name="id" column="id" type="int">
      <generator class="native" />
    </id>
    <property name="code" type="string" />
    <property name="type" type="string" />
    <property name="title" type="string" />
    <property name="description" type="text" />
    <property name="price" type="big_decimal" />
    <property name="taxable" type="string" />
    <property name="date_added" type="timestamp" />
  </class>
</hibernate-mapping>


Any help is appreciated. THANKS!

-Jon


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 09, 2007 12:56 pm 
Newbie

Joined: Fri Mar 17, 2006 7:45 pm
Posts: 3
Hello my friend. The problem might be in your build.xml file. Try changing your schemaexport taskdef to something like this:

<taskdef name="schemaexport"
classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="project.class.path"/>

<schemaexport properties="${class.root}/hibernate.properties"
quiet="no"
text="no"
drop="no"
delimiter=";"
output="${source.root}/exported-database-schema.sql">
<fileset dir="${class.root}">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>

good luck my friend! (please don't include this line in your build.xml!)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.