hibernate subclass map 父類到子類時轉換出錯(大家幫下忙)(2)

dxadnwfn發表於2007-10-26
-------------------------------------------------------------------
hibernate配置檔案:
<meta attribute="class-description">貸前調查主表</meta>
<id name="Id" type="java.lang.Long">
<meta attribute="field-description">id</meta>
<column name="ID" not-null="true" sql-type="bigint" />
<generator class="assigned" />
</id>
<discriminator column="Class" type="string" length="20"></discriminator>
<property name="type" not-null="false" type="string">
<meta attribute="field-description">貸前的型別</meta>
<column name="TYPE" not-null="false" sql-type="varchar(3)" />
</property>
<property name="typeName" not-null="false" type="string">
<meta attribute="field-description">貸前的名稱</meta>
<column name="TYPE_NAME" not-null="false"
sql-type="varchar(100)" />
</property>

...................
..................
</class>
</hibernate-mapping>


子類檔案:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.skyon.mica.frontage.entity">

<subclass name="CreditInquiryBulletin" extends="CreditInquiry"
discriminator-value="bulletin">
<map name="properties" table="CREDIT_INQUIRY_BULLETIN" cascade="all,delete-orphan" lazy="false">
<meta attribute="field-description">貸前調查從表_貸款調查報告</meta>
<key column="CREDIT_INQUIRY_ID" not-null="true" />
<map-key column="NAME" type="string" length="100" />
<element type="variable">
<column name="FIElD_TYPE"/>
<column name="VALUE" />
</element>
</map>
<join table="CREDIT_INQUIRY" fetch="select">
<key column="ID"/>
</join>
</subclass>

</hibernate-mapping>


說明這裡的子類是多個的..如以下,表結構是一樣的,只是數量量太大,所以按業務來分子表
<?xml version="1.0" encoding="GB2312" standalone="no"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.skyon.mica.frontage.entity">
<subclass name="CreditInquiryIndividualCustomer"
extends="CreditInquiry" discriminator-value="individualCustomer">

<map name="properties" table="CREDIT_INQUIRY_INDIVIDUAL_CUSTOMER" cascade="all,delete-orphan" lazy="false">
<meta attribute="field-description">貸前調查從表_對私客戶</meta>
<key column="CREDIT_INQUIRY_ID" not-null="true" />
<map-key column="NAME" type="string" length="100" />
<element type="variable">
<column name="FIElD_TYPE"/>
<column name="VALUE" />
</element>
</map>
<join table="CREDIT_INQUIRY_INDIVIDUAL_CUSTOMER_RELATING" fetch="select">
<key column="CREDIT_INQUIRY_ID"/>
</join>

</subclass>
</hibernate-mapping>


共七張相同的表


程式:

/**
* 根據一個id去得到子表的明細
* @return
*/
public String getCreditInquiryInfo() {
java.lang.Long id=creditInquiry.getId();
String type=creditInquiry.getType();
creditInquiry=creditInquiryManager.getCreditInquiry(id);
creditInquiry.getType();
if (id!=null && type!=null && !id.equals("") && !type.equals("")) {
this.returnTypeDetail(id,type);
//這裡出錯 /*CreditInquiryIndividualCustomer creditInquiryIndividualCustomer=new CreditInquiryIndividualCustomer();
creditInquiryIndividualCustomer=(CreditInquiryIndividualCustomer)creditInquiryManager.getCreditInquiry(id);*/
String page=this.returnTypePage(type);
if (page!=null) {
return page;
}
}
this.addActionError(this.getText("creditInquiry.noDetail"));
return ERROR;
}

錯誤:
java.lang.ClassCastException: com.skyon.mica.frontage.entity.CreditInquiry$$EnhancerByCGLIB$$67a4c7a6


繼三

相關文章