日期:2014-05-20  浏览次数:20912 次

非常急啊 一对多双向关联的问题 大伙帮帮忙啊!!!!!!! 88分献上
我用main 方法测试 报错内容是:
Exception in thread "main" java.lang.ClassCastException: org.hibernate.collection.PersistentSet
at T.main(T.java:50)

代码如下

Acceptence.hbm.xml
Java code
<hibernate-mapping>
    <class name="com.plat.acc.dao.Acceptence" table="syn_acceptence" schema="dbo" catalog="test">
        <id name="id" type="java.lang.Integer">
            <column name="id"/>
            <generator class="assigned" />
        </id>
        <property name="companyNo" type="java.lang.String">
            <column name="company_no" length="200" not-null="true" />
        </property>
        <property name="bankId" type="java.lang.Integer">
            <column name="bank_id"  not-null="true" />
        </property>
        <property name="factoryId" type="java.lang.Integer">
            <column name="factory_id" not-null="true" />
        </property>
        <property name="iscomplete" type="java.lang.String">
            <column name="iscomplete" length="1" />
        </property>
        <property name="lasttimesstamp" type="java.lang.String">
            <column name="lasttimesstamp" length="20" />
        </property>
        <property name="isstage" type="java.lang.String">
            <column name="isstage" length="1" />
        </property>
        <property name="remark" type="java.lang.String">
            <column name="remark" length="2000" />
        </property>
        <set name="synReceipt" table="syn_receipt" cascade="all" lazy="false" inverse="true">  
            <key column="acc_id" />  
            <one-to-many class="com.plat.receipt.dao.SynReceipt" />  
        </set>
    </class>
</hibernate-mapping>


"多"SynReceipt.hbm.xml
Java code
<hibernate-mapping>
    <class name="com.plat.receipt.dao.SynReceipt" table="syn_receipt" schema="dbo" catalog="test">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="increment" />
        </id>
        <property name="purQty" type="java.lang.Double">
            <column name="pur_qty" precision="18" />
        </property>
        <property name="purPrice" type="java.lang.Double">
            <column name="pur_price" precision="18" />
        </property>
        <property name="purAmt" type="java.lang.Double">
            <column name="pur_amt" precision="18" />
        </property>
        <property name="receiveQty" type="java.lang.Double">
            <column name="receive_qty" precision="18" />
        </property>
        <property name="receiveAmt" type="java.lang.Double">
            <column name="receive_amt" precision="18" />
        </property>
        <property name="logistic" type="java.lang.String">
            <column name="logistic" length="200" />
        </property>
        <property name="receiveDate" type="java.lang.String">
            <column name="receive_date" length="20" />
        </property>
        <many-to-one name="acceptence" class="com.plat.acc.dao.Acceptence" lazy="false"
        fetch="select" cascade="all">
            <column name="acc_id" not-null="true" />
        </many-to-one>
        <property name="productId" type="java.lang.Integer">
            <column name="product_id" not-null="true" />
        </property>
        <property name="financeNo" type="java.lang.String">
            <column name="finance_no" length="200" />
        </property>
    </class>
</hibernate-mapping>