2009-04-24 28 views
3

我正嘗試使用ant hibernatetool任務從mysql中的數據庫模式生成hbm.xml文件。 ant任務運行時沒有錯誤,但沒有生成hbm.xml文件。我在想什麼......hibernate hbm2hbmxml

下面是相關coonfigurations:

的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 /配置/ 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 /配置/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> 

回答

1

我認爲table-filter是錯誤的。

嘗試:

<table-filter match-name="%" package="com.sokrati.optimizer.dbaccess.optimizerConfig"/> 
0

試試這個

<property name="connection.username">ROOT</property> 
2

我有同樣的問題,發現以下2點有用:

  1. 正則表達式用於匹配 - 如果你想要所有的表名都是'。*',例如 <table-filter match-name=".*" package="com.sokrati.optimizer.dbaccess.optimizerConfig"/>

  2. 注意,架構名稱是區分大小寫的,所以要確保的情況下是正確的你<schema-selection>標籤在reveng.xml

0

你能否確定以下兩點。

  1. 在claaspath中保存mysql驅動jar的正確版本。 (例如,如果您使用的是MySQL 5.x,那麼您需要使用相應版本的mysql驅動程序jar。有時使用舊版本的jar,您將不會面臨錯誤,但它不會按預期工作)

  2. 如果可能,嘗試修改屬性,如:

    <property name="connection.url">jdbc:mysql://localhost:3306/?useUnicode=true&characterEncoding=utf8</property>
0

小事。正在經歷類似的問題。奇怪,我不得不爲表格過濾器指定exclude =「false」併爲我工作