繁体   English   中英

Hibernate hbm2ddl ant文件路径

[英]Hibernate hbm2ddl ant file paths

我在使用Hibernate Tools生成数据库架构时遇到了麻烦。 这是我的蚂蚁档案

<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" />

您不需要Ant即可执行此操作。 如果您仅运行一个Hibernate应用程序(例如,虚拟测试或主程序),它将为您运行hbm2ddl。

运行时,请确保.hbm.xml文件位于您的Ant类路径中。 也许这就是问题所在。 (您对build.xml的了解不够仔细,无法知道;只是将其扔在那里。)

这是一个有效的示例Hibernate配置,包括hbm2ddl。 在此之后图案化您的:

<!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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM