hibernate subclass map 父类到子类时转换出错(大家帮下忙)(2)

07-10-26 dxadnwfn
-------------------------------------------------------------------

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

继三

dxadnwfn
2007-10-26 14:55
三的地址

http://www.jdon.com/jivejdon/thread/32923.html

猜你喜欢