加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

Java-休眠hbm2hbmxml

发布时间:2020-12-14 19:32:31 所属栏目:Java 来源:网络整理
导读:我正在尝试使用ant hibernatetool任务从mysql中的数据库模式生成hbm.xml文件. ant任务运行无错误,但没有生成hbm.xml文件.我想念的是 以下是相关配置: build.xml taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classp

我正在尝试使用ant hibernatetool任务从mysql中的数据库模式生成hbm.xml文件. ant任务运行无错误,但没有生成hbm.xml文件.我想念的是…

以下是相关配置:

build.xml

<taskdef name="hibernatetool"
    classname="org.hibernate.tool.ant.HibernateToolTask"
    classpathref="3p-classpath">
</taskdef>

<target name="hbmxmlgen"
    description="Creating hbm xml files from DB">
    <hibernatetool>
        <jdbcconfiguration 
            configurationfile="src/config/hibernate.cfg.xml"
            revengfile="src/config/hibernate.reveng.xml"
            detectmanytomany="true">
        </jdbcconfiguration>
        <hbm2hbmxml destdir="${mappings.dir}"/>
    </hibernatetool>
</target>

src / config / hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8" ?> <!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/?useUnicode=true&characterEncoding=utf8</property>
        <property name="connection.username">root</property>
        <property name="connection.pool_size">1</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="current_session_context_class">thread</property>
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="show_sql">true</property>
    </session-factory> </hibernate-configuration>

src / config / reveng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">

<hibernate-reverse-engineering>
    <schema-selection match-schema="optimizer_config"/>
    <type-mapping>
        <sql-type jdbc-type="VARCHAR" hibernate-type="string"/>
        <sql-type jdbc-type="NUMERIC" hibernate-type="java.lang.Long" />
        <sql-type jdbc-type="INTEGER" hibernate-type="java.lang.Integer" />
        <sql-type jdbc-type="DECIMAL" hibernate-type="java.lang.Double" />
    </type-mapping>
    <table-filter match-name="*" package="com.sokrati.optimizer.dbaccess.optimizerConfig"/>
</hibernate-reverse-engineering>
最佳答案
我遇到了同样的问题,发现以下两点有用:

>如果要所有表,则用于匹配名称的正则表达式为’.*’,例如
< table-filter match-name =“.*” package =“ com.sokrati.optimizer.dbaccess.optimizerConfig” />
>请注意,模式名称区分大小写,因此请确保在< schema-selection>中使用大小写正确在reveng.xml中标记.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读