-->
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: export-schema using ant (&netbeans6)
PostPosted: Fri Apr 25, 2008 7:44 pm 
Newbie

Joined: Fri Apr 25, 2008 7:39 pm
Posts: 3
Can anyone get org.hibernate.tool.ant.HibernateToolTask to export-schema into MySql ?

I'm using netbeans and ant.

it's worth noting that the tutorial in the doc folder with the hibernate download
( main site) works by merely including
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
in the hibernate cfg file for some reason...

retrying with this setup..

build.xml:

<project name="hibernate_eventMgr" default="compile">
<property name="src.dir" value="${basedir}/src"/>
<property name="build.dir" value="${basedir}/classes"/>
<property name="lib.dir" value="C:/jars/"/>

<property name="hibernate.version" value="3.0"/>
<property name="mysql.jdbc.version" value="5.0.7"/>

<path id="libraries">
<fileset dir="${lib.dir}">
<include name="hibernate/*.jar"/>
<include name="dbasecon/mysql-connector-java-5.0.7-bin.jar"/>
<include name="logging/*.jar"/>
<include name="testing/junit/junit-4.4.jar"/>
</fileset>
</path>
<path id="toolslib">
<path location="${lib.dir}/hib-tools/hibernate-tools.jar" />
<path location="${lib.dir}/logging/commons-logging-1.0.4.jar" />
<path location="${lib.dir}/logging/dom4j-1.6.1.jar" />
<path location="${lib.dir}/hibernate/hibernate3.jar" />
<path location="${lib.dir}/hib-tools/freemarker.jar" />
<path location="${lib.dir}/dbasecon/mysql-connector-java-5.0.7-bin.jar" />

</path>
<path id="project.classpath">
<pathelement location="${build.dir}" />
</path>

<path id="runtime.classpath">
<path refid="project.classpath"/>
<path refid="libraries"/>
<pathelement location="${jdbc.driver.jar}"/>
<pathelement location="${src.dir}"/>
</path>
<target name="clean">
<delete dir="${build.dir}"/>
<mkdir dir="${build.dir}"/>
</target>
<target name="compile" depends="clean, copy-resources">
<javac srcdir="${src.dir}"
destdir="${build.dir}"
classpathref="libraries"/>
<copy todir="${build.dir}">
<fileset dir="${src.dir}" >
<include name="**/*.xml" />
</fileset>
</copy>
</target>
<target name="copy-resources">
<copy todir="${build.dir}">
<fileset dir="${src.dir}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="run" depends="compile">
<java fork="true" classname="com.manning.hq.ch04.EventLoader" classpathref="${lib.dir}/hibernate/*.jar">
<classpath path="${build.dir}"/>
</java>
<echo>If you see this, it works!!!${build.dir}</echo>
</target>
<!-- off the main site -->
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib" />

<target name="schema-drop" depends="compile">
<hibernatetool destdir="${build.dir}">
<configuration configurationfile="${build.dir}/hibernate.cfg.xml" />
<hbm2ddl drop="true" create="false" export="true" update="false"/>
</hibernatetool>
</target>
<target name="schema-recreate" depends="compile">
<hibernatetool destdir="${build.dir}">
<configuration configurationfile="${build.dir}/hibernate.cfg.xml" />
<hbm2ddl drop="true" create="true" export="true" update="false"/>
</hibernatetool>
</target>

<target name="schema-docu" depends="compile" description="Generate a html description of the mappings">
<hibernatetool destdir="hibernate-html">
<configuration configurationfile="${build.dir}/hibernate.cfg.xml" />
<hbm2doc/>
</hibernatetool>
</target>
</project>

my hibernate.cfg.xml:

<project name="hibernate_eventMgr" default="compile">
<property name="src.dir" value="${basedir}/src"/>
<property name="build.dir" value="${basedir}/classes"/>
<property name="lib.dir" value="C:/jars/"/>

<property name="hibernate.version" value="3.0"/>
<property name="mysql.jdbc.version" value="5.0.7"/>

<path id="libraries">
<fileset dir="${lib.dir}">
<include name="hibernate/*.jar"/>
<include name="dbasecon/mysql-connector-java-5.0.7-bin.jar"/>
<include name="logging/*.jar"/>
<include name="testing/junit/junit-4.4.jar"/>
</fileset>
</path>
<path id="toolslib">
<path location="${lib.dir}/hib-tools/hibernate-tools.jar" />
<path location="${lib.dir}/logging/commons-logging-1.0.4.jar" />
<path location="${lib.dir}/logging/dom4j-1.6.1.jar" />
<path location="${lib.dir}/hibernate/hibernate3.jar" />
<path location="${lib.dir}/hib-tools/freemarker.jar" />
<path location="${lib.dir}/dbasecon/mysql-connector-java-5.0.7-bin.jar" />

</path>
<path id="project.classpath">
<pathelement location="${build.dir}" />
</path>

<path id="runtime.classpath">
<path refid="project.classpath"/>
<path refid="libraries"/>
<pathelement location="${jdbc.driver.jar}"/>
<pathelement location="${src.dir}"/>
</path>
<target name="clean">
<delete dir="${build.dir}"/>
<mkdir dir="${build.dir}"/>
</target>
<target name="compile" depends="clean, copy-resources">
<javac srcdir="${src.dir}"
destdir="${build.dir}"
classpathref="libraries"/>
<copy todir="${build.dir}">
<fileset dir="${src.dir}" >
<include name="**/*.xml" />
</fileset>
</copy>
</target>
<target name="copy-resources">
<copy todir="${build.dir}">
<fileset dir="${src.dir}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="run" depends="compile">
<java fork="true" classname="com.manning.hq.ch04.EventLoader" classpathref="${lib.dir}/hibernate/*.jar">
<classpath path="${build.dir}"/>
</java>
<echo>If you see this, it works!!!${build.dir}</echo>
</target>
<!-- off the main site -->
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib" />

<target name="schema-drop" depends="compile">
<hibernatetool destdir="${build.dir}">
<configuration configurationfile="${build.dir}/hibernate.cfg.xml" />
<hbm2ddl drop="true" create="false" export="true" update="false"/>
</hibernatetool>
</target>
<target name="schema-recreate" depends="compile">
<hibernatetool destdir="${build.dir}">
<configuration configurationfile="${build.dir}/hibernate.cfg.xml" />
<hbm2ddl drop="true" create="true" export="true" update="false"/>
</hibernatetool>
</target>

<target name="schema-docu" depends="compile" description="Generate a html description of the mappings">
<hibernatetool destdir="hibernate-html">
<configuration configurationfile="${build.dir}/hibernate.cfg.xml" />
<hbm2doc/>
</hibernatetool>
</target>
</project>


now gives this error:

clean:
Deleting directory C:\Documents and Settings\John Okrasa.ANTENNA\My Documents\NetBeansProjects\hibernate_eventMgr\classes
Created dir: C:\Documents and Settings\John Okrasa.ANTENNA\My Documents\NetBeansProjects\hibernate_eventMgr\classes
copy-resources:
Copying 6 files to C:\Documents and Settings\John Okrasa.ANTENNA\My Documents\NetBeansProjects\hibernate_eventMgr\classes
compile:
Compiling 3 source files to C:\Documents and Settings\John Okrasa.ANTENNA\My Documents\NetBeansProjects\hibernate_eventMgr\classes
schema-recreate:
Executing Hibernate Tool with a Standard Configuration
1. task: hbm2ddl (Generates database schema)
An exception occurred while running exporter #2:hbm2ddl (Generates database schema)
To get the full stack trace run ant with -verbose
org.hibernate.MappingNotFoundException: resource: com/manning/hq/ch04/Event.hbm.xml not found
A resource located at com/manning/hq/ch04/Event.hbm.xml was not found.
Check the following:
1) Is the spelling/casing correct ?
2) Is com/manning/hq/ch04/Event.hbm.xml available via the classpath ?
3) Does it actually exist ?
org.hibernate.MappingNotFoundException: resource: com/manning/hq/ch04/Event.hbm.xml not found



classpath,classpath,... I checked it thoroughly... why can't it see it ???


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 27, 2008 3:40 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Try using fileset insite the <configuration> tag to include the hbm files. By the way, where have you placed the mapping files. Can ant see it? I mean have you set the location in "toolslib" path definition that you use for hibernatetools task?

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 04, 2008 8:04 pm 
Newbie

Joined: Fri Apr 25, 2008 7:39 pm
Posts: 3
gave up on using the hibernate-tools.jar and went with the way it's done in the tutorial on the hibernate.org site....

so:

<?xml version="1.0"?>
<!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="connection.username">root</property>
<property name="connection.password">stella</property>
<property name="connection.url">jdbc:mysql://localhost/events_calendar</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<property name="hbm2ddl.auto">create</property>
<mapping resource="com/manning/hq/ch04/Event.hbm.xml"/>
<mapping resource="com/manning/hq/ch04/Location.hbm.xml"/>
</session-factory>
</hibernate-configuration>

and

<project name="hibernate_eventMgr" default="compile">

<property name="sourcedir" value="${basedir}/src"/>
<property name="targetdir" value="${basedir}/bin"/>
<property name="librarydir" value="C:/jars/"/>

<path id="libraries">
<fileset dir="${librarydir}">
<include name="hibernate/*.jar"/>
<include name="logging/*.jar"/>
<include name="dbasecon/mysql-connector-java-5.0.7-bin.jar"/>
</fileset>
</path>

<target name="clean">
<delete dir="${targetdir}"/>
<mkdir dir="${targetdir}"/>
</target>

<target name="compile" depends="clean, copy-resources">
<javac srcdir="${sourcedir}"
destdir="${targetdir}"
classpathref="libraries"/>
</target>

<target name="copy-resources">
<copy todir="${targetdir}">
<fileset dir="${sourcedir}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>

<target name="run" depends="compile">
<java fork="true" classname="com.manning.hq.ch04.EventLoader" classpathref="libraries">
<classpath path="${targetdir}"/>
</java>
</target>
<target name="war" depends="compile">
<war destfile="hibernate-tutorial.war" webxml="web.xml">
<lib dir="${librarydir}">
<exclude name="jsdk*.jar"/>
</lib>

<classes dir="${targetdir}"/>
</war>
</target>

</project>

will export the schema and I have to comment out the config line in bold once it's created..

tried putting the path reference in different places for the *.hbm.xml files in the previous build files to no avail...

Has anyone had any luck setting build targets in the build.xml file for this feature?

P.S. thanks for your input tho !


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.