首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hibernate hbm2ddl ant文件路径

Hibernate hbm2ddl ant文件路径
EN

Stack Overflow用户
提问于 2010-09-16 17:44:19
回答 1查看 2.2K关注 0票数 1

我在使用Hibernate工具生成数据库模式时遇到了问题。这是我的ant文件

代码语言:javascript
复制
<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

我的文件系统路径层次结构如下:

代码语言:javascript
复制
+resources
   -hibernate_mappings
      -Address.hbm.xml
      -User.hbm.xml
      -etc..
   -hibernate.cfg.xml
   -build.xml

我在hibernate.hbm.xml中定义了如下映射:

代码语言:javascript
复制
<mapping resource="hibernate_mappings/Address.hbm.xml" />
EN

回答 1

Stack Overflow用户

发布于 2010-09-16 18:11:55

你不需要Ant来做这件事。如果您只运行一个Hibernate应用程序(例如,虚拟测试或主应用程序),它将为您运行hbm2ddl。

确保在运行时.hbm.xml文件位于Ant类路径中。也许这就是问题所在。(没有足够仔细地查看您的build.xml以了解;只是将其抛出。)

下面是一个有效的Hibernate配置示例,包括hbm2ddl。在此之后设计你的模式:

代码语言:javascript
复制
<!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.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/hibernate?autoReconnect=true</property>
        <property name="connection.username">hibernate</property>
        <property name="connection.password">hibernate</property>
        <property name="connection.pool_size">1</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
        <property name="show_sql">true</property>
        <property name="generate_statistics">true</property>
        <property name="query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="cache.use_minimal_puts">false</property>
        <property name="cache.use_query_cache">false</property>
        <property name="order_updates">false</property>
        <property name="hbm2ddl.auto">create-drop</property>
        <property name="current_session_context_class">thread</property>

        <mapping resource="hibernate/policy/persistence/hibernate/Person.hbm.xml"/>

    </session-factory>
</hibernate-configuration>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3725452

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档