Thanks to this forum I've got hibernate running great with my latest project. I am hoping that someone can help me come up wih a more "modular" ant file. My ultimate goal here is to make an ant file that will work unedited, even if I add mapping files for new classes to my system.
Here's my current setup as far as ant is concerned, shortened for clarity:
Code:
<project name="Try Hibernate" default="all" basedir=".">
<path id="mappingfiles.path">
<fileset dir="${mapping.home}">
<include name="**/*.hbm.xml" />
</fileset>
</path>
<!-- ULTIMATELY WANT TO USE ONE LIST LIKE THIS -->
<pathconvert pathsep=" " property="mappingfiles.list" refid="mappingfiles.path">
</pathconvert>
<!-- ONE MASTER LIST LIKE THIS WOULD DO THOUGH -->
<property name="mappingfiles.list" value="${src.home}/com/txdx/event.hbm.xml
${src.home}/com/txdx/anotherfile.hbm.xml
${src.home}/com/txdx/pojo/Team.hbm.xml
${src.home}/com/txdx/pojo/Player.hbm.xml" />
<!-- loops thru all the .hbm.xml files -->
<target name="schemaExport">
<java classname="net.sf.hibernate.tool.hbm2ddl.SchemaExport" fork="true">
<!-- ultimate solution
<arg value="${mappingfiles.list}" />
-->
<!-- this way gives a malformedurlexception -->
<arg value="${src.home}/com/txdx/event.hbm.xml ${src.home}/com/txdx/anotherfile.hbm.xml ${src.home}/com/txdx/pojo/Team.hbm.xml ${src.home}/com/txdx/pojo/Player.hbm.xml" />
<!-- this is how I have to do it now
<arg value="anotherfile.hbm.xml" />
<arg value="$Team.hbm.xml" />
<arg value="Player.hbm.xml" />
-->
<classpath refid="lib.class.path" />
</java>
<!--
<foreach list="${mappingfiles.list}" delimiter=" " target="ExportSchema" param="mappingfiles.item" trim="true">
</foreach>
-->
</target>
<target name="dont use any below here" />
<!-- called by looping task in SchemaExport -->
<target name="ExportSchema">
<java classname="net.sf.hibernate.tool.hbm2ddl.SchemaExport" fork="true">
<arg value="${mappingfiles.item}" />
<classpath refid="lib.class.path" />
</java>
</target>
</project>
I want to eventually get the pathconvert that generates my list of mapping files to work so that I can just use this list in my schemaExport and schemaUpdate targets. This way I can add mapping files if needed and just run my ant tasks and boom -- I'm testing my changes right away.
Well this doesn't work at all right now. Two things:
(1) File order is important. Team and Player share a many-to-one relationship, so I need to have these java classes see Team, then Player. The list generated by the pathconvert takes them alphabetaically. OK, so maybe I can live with a master list of mapping files that I can manually add items to as I add classes. Clumsy but workable.
(2) No! Either because of ant or the classes themselves, I have to put in a separate arg entry for each mapping file. Instead of just being able to say this:
Code:
<target name="schemaExport">
<java classname="SchemaExport" fork="true">
<arg value="a.xml b.xml c.xml" />
<classpath refid="lib.class.path" />
</java>
</target>
or ultimately like this:
Code:
<target name="schemaExport">
<java classname="SchemaExport" fork="true">
<arg value="${one_big_mapping.list}" />
<classpath refid="lib.class.path" />
</java>
</target>
I have to say it like this:
Code:
<target name="schemaExport">
<java classname="SchemaExport" fork="true">
<arg value="a.xml" />
<arg value="b.xml" />
<arg value="c.xml" />
<classpath refid="lib.class.path" />
</java>
</target>
And then I have to repeat the same thing all over again for the schemaUpdate target and any other target that processes the mapping files.
The SchemaUpdate and SchemaExport classes seem to require a separate arg value for each one, rather than being able to take <arg value=""> as a list.
Am I missing something here? As it stands, I would have to do a lot of list maintenance to get this all neat and tidy.