Let me try this again:
I'm using Hibernate 2.1.2. My mapping documents are irrelevant, because they work, and the code between openSession() and session.close() also works.
What I'm trying to do is have my SchemaExportTask in Ant use my config file instead of a properties file. I'd prefer to have only one, and since I can list my mappings in the config file (and, as far as I know, can't in the properties file, requiring loading them in my source code) I'd prefer a config file.
Using properties, SchemaExportTask works quite nicely, and my current workaround is to maintain both a properties file and a config file so that I can use properties with SchemaExportTask and config in my source files. Using either properties or config file, vanilla Hibernate code in classes works quite nicely. In fact, I know my config file is visible on my class path (the same one I'm giving SchemaExportTask) because
Code:
SessionFactory sf = new Configuration().configure().buildSessionFactory();
works wonderfully, and the log shows that it's using hibernate.cfg.xml as its configuration file.
However, if I try to use a config file for SchemaExportTask as shown in this excerpt of my build file
Code:
<target name="create-db" depends="copy-jars">
<taskdef
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="project.class.path"
name="schemaexport"/>
<schemaexport
config="${build.dir}/hibernate.cfg.xml"
delimiter=";"
drop="false"
output="schema.sql"
quiet="false"
text="false"
<fileset dir="${build.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>
</target>
I get the following exception:
create-db:
[schemaexport] 05:22:44,010 INFO Environment:462 - Hibernate 2.1.2
[schemaexport] 05:22:44,085 INFO Environment:491 - hibernate.properties not found
[schemaexport] 05:22:44,104 INFO Environment:519 - using CGLIB reflection optimizer
[schemaexport] 05:22:44,277 INFO Configuration:854 - configuring from resource: /Applications/eclipse/workspace/dupontmanual/context/WEB-INF/classes/hibernate.cfg.xml
[schemaexport] 05:22:44,331 INFO Configuration:826 - Configuration resource: /Applications/eclipse/workspace/dupontmanual/context/WEB-INF/classes/hibernate.cfg.xml
[schemaexport] 05:22:44,340 WARN Configuration:830 - /Applications/eclipse/workspace/dupontmanual/context/WEB-INF/classes/hibernate.cfg.xml not found
BUILD FAILED: /Applications/eclipse/workspace/dupontmanual/build.xml:61: Schema text failed: /Applications/eclipse/workspace/dupontmanual/context/WEB-INF/classes/hibernate.cfg.xml not found
The problem is that hibernate.cfg.xml really does exist, and right where ant appears to be looking for it. I can prove it, because when I run a JUnit test, I get:
05:25:00,433 INFO Environment:462 - Hibernate 2.1.2
05:25:00,453 INFO Environment:491 - hibernate.properties not found
05:25:00,479 INFO Environment:519 - using CGLIB reflection optimizer
05:25:00,507 INFO Configuration:854 - configuring from resource: /hibernate.cfg.xml
05:25:00,524 INFO Configuration:826 - Configuration resource: /hibernate.cfg.xml
05:25:02,443 INFO Configuration:311 - Mapping resource: org/dupontmanual/db/User.hbm.xml
05:25:03,044 INFO Binder:229 - Mapping class: org.dupontmanual.db.User -> users
05:25:03,460 INFO Configuration:311 - Mapping resource: org/dupontmanual/db/Password.hbm.xml
05:25:03,687 INFO Binder:229 - Mapping class: org.dupontmanual.db.Password -> passwords
05:25:03,699 INFO Configuration:1017 - Configured SessionFactory: null
which shows that the config file is on the class path.
Incidentally, leaving out the ${build.dir} before the path to the config file makes no difference except that the path is slightly different:
[schemaexport] 05:27:45,017 INFO Configuration:854 - configuring from resource: hibernate.cfg.xml
[schemaexport] 05:27:45,051 INFO Configuration:826 - Configuration resource: hibernate.cfg.xml
[schemaexport] 05:27:45,058 WARN Configuration:830 - hibernate.cfg.xml not found
BUILD FAILED: /Applications/eclipse/workspace/dupontmanual/build.xml:61: Schema text failed: hibernate.cfg.xml not found
Total time: 5 seconds
Now, admittedly, config is not documented as a legal attribute of SchemaExportTask, but there is a setConfig() method, and it does seem to be trying to load it.
Any ideas what gives here?
Thanks,
Todd