Hibernate hbm2ddl ant 文件路径
我在使用 Hibernate Tools 生成数据库架构时遇到问题。这是我的ant文件
<project name="Schema generator for MySQL database" basedir=".">
<description>
This file is used for running Hibernate Tools Ant task.
It is used to generate database schema based on hibernate configuration
</description>
<path id="toolslib">
<path location="lib/hibernate-tools.jar" />
<path location="lib/hibernate-3.2.4.ga.jar" />
<path location="lib/freemarker.jar" />
<path location="lib/mysql-connector-java-5.1.13" />
<path location="lib/dom4j-1.6.1.jar" />
<path location="hibernate_mappings/Address.hbm.xml" />
</path>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="toolslib" />
<hibernatetool destdir="${build.dir}/generated">
<classpath>
<path location="${build.dir}/classes" />
</classpath>
<configuration configurationfile="hibernate.cfg.xml" />
<hbm2ddl />
<hbm2dao />
</hibernatetool>
</project>
,运行ant任务时出现此错误:
C:\ work \ gwt_workspace \ billing-cms \ dao \ src \ main \ resources \ build.xml:19:org.hibernate.MappingNotFoundException:资源:hibernate_mappings / Address未找到 .hbm.xml
我的文件系统路径层次结构如下:
+resources
-hibernate_mappings
-Address.hbm.xml
-User.hbm.xml
-etc..
-hibernate.cfg.xml
-build.xml
我在 hibernate.hbm.xml 中定义了映射,如下所示:
<mapping resource="hibernate_mappings/Address.hbm.xml" />
I am having troubles with generating database schema with Hibernate Tools. This is my ant file
<project name="Schema generator for MySQL database" basedir=".">
<description>
This file is used for running Hibernate Tools Ant task.
It is used to generate database schema based on hibernate configuration
</description>
<path id="toolslib">
<path location="lib/hibernate-tools.jar" />
<path location="lib/hibernate-3.2.4.ga.jar" />
<path location="lib/freemarker.jar" />
<path location="lib/mysql-connector-java-5.1.13" />
<path location="lib/dom4j-1.6.1.jar" />
<path location="hibernate_mappings/Address.hbm.xml" />
</path>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="toolslib" />
<hibernatetool destdir="${build.dir}/generated">
<classpath>
<path location="${build.dir}/classes" />
</classpath>
<configuration configurationfile="hibernate.cfg.xml" />
<hbm2ddl />
<hbm2dao />
</hibernatetool>
</project>
I get this error when running ant task:
C:\work\gwt_workspace\billing-cms\dao\src\main\resources\build.xml:19: org.hibernate.MappingNotFoundException: resource: hibernate_mappings/Address.hbm.xml not found
My filesystem path hierarchy is like this:
+resources
-hibernate_mappings
-Address.hbm.xml
-User.hbm.xml
-etc..
-hibernate.cfg.xml
-build.xml
I have my mappings defined inside hibernate.hbm.xml like this:
<mapping resource="hibernate_mappings/Address.hbm.xml" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不需要 Ant 来做这件事。如果您只运行一个 Hibernate 应用程序(例如,虚拟测试或主应用程序),它会为您运行 hbm2ddl。
确保运行时 .hbm.xml 文件位于 Ant 类路径中。也许这就是问题所在。 (没有仔细查看您的 build.xml 来了解;只是将其扔在那里。)
这是一个有效的 Hibernate 配置示例,包括 hbm2ddl。按照这个图案设计你的:
You don't need Ant to do this. If you just run one Hibernate app (e.g., a dummy test or main), it'll run hbm2ddl for you.
Make sure the .hbm.xml files are in your Ant classpath when you run. Perhaps that's the problem. (Didn't look closely enough at your build.xml to know; just throwing it out there.)
Here's a sample Hibernate config that works, including hbm2ddl. Pattern yours after this: