Java-休眠hbm2hbmxml

前端之家收集整理的这篇文章主要介绍了Java-休眠hbm2hbmxml 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

以下是相关配置:

build.xml

  1. <taskdef name="hibernatetool"
  2. classname="org.hibernate.tool.ant.HibernateToolTask"
  3. classpathref="3p-classpath">
  4. </taskdef>
  5. <target name="hbmxmlgen"
  6. description="Creating hbm xml files from DB">
  7. <hibernatetool>
  8. <jdbcconfiguration
  9. configurationfile="src/config/hibernate.cfg.xml"
  10. revengfile="src/config/hibernate.reveng.xml"
  11. detectmanytomany="true">
  12. </jdbcconfiguration>
  13. <hbm2hbmxml destdir="${mappings.dir}"/>
  14. </hibernatetool>
  15. </target>

src / config / hibernate.cfg.xml

  1. <?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE hibernate-configuration PUBLIC
  2. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  3. "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration>
  4. <session-factory>
  5. <property name="connection.driver_class">com.MysqL.jdbc.Driver</property>
  6. <property name="connection.url">jdbc:MysqL://localhost/?useUnicode=true&characterEncoding=utf8</property>
  7. <property name="connection.username">root</property>
  8. <property name="connection.pool_size">1</property>
  9. <property name="dialect">org.hibernate.dialect.MysqLDialect</property>
  10. <property name="current_session_context_class">thread</property>
  11. <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
  12. <property name="show_sql">true</property>
  13. </session-factory> </hibernate-configuration>

src / config / reveng.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
  3. <hibernate-reverse-engineering>
  4. <schema-selection match-schema="optimizer_config"/>
  5. <type-mapping>
  6. <sql-type jdbc-type="VARCHAR" hibernate-type="string"/>
  7. <sql-type jdbc-type="NUMERIC" hibernate-type="java.lang.Long" />
  8. <sql-type jdbc-type="INTEGER" hibernate-type="java.lang.Integer" />
  9. <sql-type jdbc-type="DECIMAL" hibernate-type="java.lang.Double" />
  10. </type-mapping>
  11. <table-filter match-name="*" package="com.sokrati.optimizer.dbaccess.optimizerConfig"/>
  12. </hibernate-reverse-engineering>
最佳答案
我遇到了同样的问题,发现以下两点有用:

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

猜你在找的Java相关文章