国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

bug? Hbm2JavaTask無法實現joined-subclass單獨配置文件(2.1.2)

2019-11-18 14:53:39
字體:
來源:轉載
供稿:網友

假如你并不打算使用類繼續結構并不是很有必要閱讀本文。請先閱讀我寫的另一篇文章 "使用hibernate擴展工具Hbm2javaTask根據配置文件生成持久化對象類(2.1.2)"1.在文檔第8章(hibernate/doc/reference/zh-cn/Html/inheritance.HTML)有提到

“每個子類一個表”的映射是這樣的:

<class name="Payment" table="PAYMENT"> <id name="id" type="long" column="PAYMENT_ID"> <generator class="native"/> </id> <PRoperty name="amount" column="AMOUNT"/> ... <joined-subclass name="CreditCardPayment" table="CREDIT_PAYMENT"> <key column="PAYMENT_ID"/> ... </joined-subclass> <joined-subclass name="CashPayment" table="CASH_PAYMENT"> <key column="PAYMENT_ID"/> ... </joined-subclass> <joined-subclass name="ChequePayment" table="CHEQUE_PAYMENT"> <key column="PAYMENT_ID"/> ... </joined-subclass></class>

2.文檔第5章(hibernate/doc/reference/zh-cn/HTML/mapping.HTML)有提到

答應在獨立的映射文檔中定義subclass和joined-subclass,直接位于hibernate-mapping下。這就可以讓你每次擴展你的類層次的時候,加入新的映射文件就行了。在子類的映射中你必須指定一個extents屬性,指明先前已經映射過的超類。使用這個功能的時候,一定要注重映射文件的排序是非常重要的!

<hibernate-mapping> <subclass name="eg.subclass.DomesticCat" extends="eg.Cat" discriminator-value="D"> <property name="name" type="string"/> </subclass></hibernate-mapping>
3.根據以上兩點,偶根據第8章的PAYMENT創建了一個工程,把joined-subclass移了出來,現在工程目錄結構如下 Payment  <dir>-src  <dir>-hbm  <dir>  -payment  <dir>    -Payment.hbm.xml    -CreditCardPayment.hbm.XML    -CashPayment.hbm.XML-classes  <dir>-lib  <dir>-build.XML-hibernate.codegen.XML-log4j.properties4. 本文不再重復build.XML, hibernate.codegen.XML, log4j.properties三個文件的內容??稍?quot;使用hibernate擴展工具Hbm2JavaTask根據配置文件生成持久化對象類(2.1.2)"一文查看這三個文件的內容。此處僅列出.hbm.XML文件內容。  4.1 Payment.hbm.XML<?XML version="1.0" encoding="gbk"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"><hibernate-mapping>  <class name="payment.Payment" table="PAYMENT">    <id name="id" type="long" column="PAYMENT_ID">      <generator class="native"/>    </id>    <property name="amount" column="AMOUNT" type="long"/>  </class></hibernate-mapping>  4.2 CreditCardPayment.hbm.XML
<?XML version="1.0" encoding="gbk"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"><hibernate-mapping><joined-subclass name="payment.CreditCardPayment" table="CREDIT_PAYMENT" extends="payment.Payment"> <key column="PAYMENT_ID"/></joined-subclass></hibernate-mapping>
  4.3 CashPayment.hbm.XML
<?XML version="1.0" encoding="gbk"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"><hibernate-mapping><joined-subclass name="payment.CashPayment" table="CASH_PAYMENT" extends="payment.Payment"> <key column="PAYMENT_ID"/></joined-subclass></hibernate-mapping>
5.在命令行進入工程目錄,運行ant,發生錯誤,要害提示如下: net.sf.hibernate.MappingException: Cannot extend unmapped class payment.Payment6.查錯過程我就不說了,比較無聊,只說一下問題出在哪里  6.1 Hbm2JavaTask里對配置文件列表做了循環,每個文件單獨處理,所以有關聯的類就找不到了。   6.2 但是CodeGenerator類也有不妥,沒有考慮文件排列問題,因為子類可能先于父類被處理。7.下面帖出兩個修改過的文件代碼。在修改的地方加了中文注釋。  7.1 net.sf.hibernate.tool.hbm2java.Hbm2JavaTask
package net.sf.hibernate.tool.hbm2java;import java.io.File;import java.io.PrintWriter;import java.io.StringWriter;import java.util.ArrayList;import java.util.List;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.DirectoryScanner;import org.apache.tools.ant.Task;import org.apache.tools.ant.types.FileSet;import org.apache.tools.ant.types.Path;import org.apache.tools.ant.types.Reference;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;/** * Task for hbm2java (Hibernates codegenerator) * * * @author GBegley and max * */public class Hbm2JavaTask extends Task { private static final Log log = LogFactory.getLog(CodeGenerator.class); private File configurationFile; private Path compileClasspath; private File outputDir; private List filesets = new ArrayList(); /** * Set a hbm2java <literal>config.XML</literal> configuration file * @param the file name */ public void setConfig(File configurationFile) { this.configurationFile = configurationFile; } /** * Set the classpath to be used for this compilation. * * @param classpath an Ant Path object containing the compilation classpath. */ public void setClasspath(Path classpath) { if (compileClasspath == null) { compileClasspath = classpath; } else { compileClasspath.append(classpath); } } /** Gets the classpath to be used for this compilation. */ public Path getClasspath() { return compileClasspath; } /** * Adds a path to the classpath. */ public Path createClasspath() { if (compileClasspath == null) { compileClasspath = new Path(getProject()); } return compileClasspath.createPath(); } /** * Adds a reference to a classpath defined elsewhere. */ public void setClasspathRef(Reference r) { createClasspath().setRefid(r); } /** * Adds a set of files to translate. */ public void addFileset(FileSet set) { filesets.add(set); } /** * Sets the output directory. * * @param binDirectory directory */ public void setOutput(File outDirectory) { this.outputDir = outDirectory; } public void execute() throws BuildException { List fileList = getTargetFiles(); if (fileList.size() == 0) return; log("Processing " + fileList.size() + " files."); try { log("Building hibernate objects"); //這個循環是錯誤1, //for (int i = 0; i < fileList.size(); i++) { // processFile(outputDir, (File) fileList.get(i)); //} //要修改processFile方法 processFile(outputDir, fileList); } catch (Throwable t) { StringWriter sw = new StringWriter(); t.printStackTrace(new PrintWriter(sw)); throw new BuildException("Caused by:/n" + sw.toString()); } } /** * * * Comment: * The initial ant task had some initial

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 青阳县| 延边| 新昌县| 囊谦县| 怀仁县| 威海市| 日土县| 宜君县| 达孜县| 新泰市| 永吉县| 衡东县| 兴文县| 阳谷县| 赤壁市| 怀安县| 浙江省| 阿克苏市| 连江县| 屏东县| 蒙自县| 昌邑市| 临潭县| 台前县| 郧西县| 长治县| 呼和浩特市| 南京市| 德令哈市| 文水县| 邢台县| 昌平区| 宝清县| 伊川县| 河北区| 海阳市| 曲靖市| 化隆| 历史| 达拉特旗| 宁德市|