I loaded a hibernate persisted object using session.load(id) and Hibernate.initialize the collections contained with the object. When I attempted to write out the object graph using java.bean.XMLEncoder, I ended up with the following exception:
Code:
java.lang.IllegalArgumentException: object is not an instance of declaring class
java.lang.Exception: discarding statement XMLEncoder0.writeObject(Quotation$$EnhancerByCGLIB$$bc2ff890);
It is evident that the CGLIB enhanced object is being passed to XMLEncoder. Here is the code that is attempting to write:
Code:
Quotation q = iman.getQuotation(new Long(41));
XMLEncoder e = null;
try {
e = new XMLEncoder(new FileOutputStream("Quotation.xml"));
e.writeObject(q); // this will write the entire object graph.
}
catch(Exception ex) {
System.out.println(ex);
}
How do I pass the "right" object to XMLEncoder's writeObject method?Here is the hbm for the object in question:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<!-- $Id: Quotation.hbm.xml,v 1.1 2004/01/20 12:19:40 aslam Exp $ -->
<hibernate-mapping schema="CPO2">
<class name="com.cgc.esd.purchasing.Quotation" table="CPO_RFQ_QUOTS"
proxy="com.cgc.esd.purchasing.Quotation">
<id name="id" column="QUOT_ID" type="java.lang.Long"
unsaved-value="null">
<generator class="native">
<param name ="sequence">CPO_RFQ_QUOTS_S</param>
</generator>
</id>
<property name="quotationCreationDate" column="QUOT_CREATION_DATE" type="timestamp"/>
<property name="supplierQuotationId" column="SUPL_QUOT_ID" type="java.lang.Long"/>
<property name="statusLookup" column="QUOT_STATUS_LKP" type="string"/>
<property name="termsOfPaymentLookup" column="TERMS_OF_PAYMENT_LKP" type="string"/>
<property name="modeOfPaymentLookup" column="MODE_OF_PAYMENT_LKP" type="string"/>
<property name="typeLookup" column="QUOT_TYPE_LKP" type="string"/>
<property name="deliveryTerms" column="DELIVERY_TERMS" type="string"/>
<property name="shipmentTermsLookup" column="SHIPMENT_TERMS_LKP" type="string"/>
<property name="freightAndOtherCharges" column="FRGT_AND_OTHER_CHARGES" type="java.lang.Long"/>
<property name="receiveDate" column="QUOT_RECEIVE_DATE" type="timestamp"/>
<property name="shipmentFromLookup" column="SHIPMENT_FROM_LKP" type="string"/>
<property name="currencyLookup" column="CURRENCY_LKP" type="string"/>
<property name="discountPercentage" column="DISCOUNT_PCT" type="java.lang.Long"/>
<property name="discountValue" column="DISCOUNT_VAL" type="java.lang.Long"/>
<property name="importRebatePercentage" column="IMPORT_REBATE_PCT" type="java.lang.Long"/>
<property name="importRebateValue" column="IMPORT_REBATE_VAL" type="java.lang.Long"/>
<property name="remarks" column="REMARKS" type="string"/>
<property name="agentCode" column="AGENT_CODE" type="java.lang.Long"/>
<property name="validFrom" column="QUOT_VALID_FROM" type="timestamp"/>
<property name="agentCommission" column="AGENT_COMMISSION" type="java.lang.Long"/>
<property name="validTill" column="QUOT_VALID_TILL" type="timestamp"/>
<property name="supplierBankName" column="SUPL_BANK_NAME" type="string"/>
<property name="bankBranchName" column="BANK_BRANCH_NAME" type="string"/>
<property name="bankAccountNumber" column="BANK_ACCT_NUM" type="string"/>
<property name="inspectionAtLookup" column="INSPECTION_AT_LKP" type="string"/>
<property name="lastUpdate" column="LAST_UPDATE_DATE" type="timestamp"></property>
<property name="createByUserId" column="CREATED_BY" type="java.lang.Long"/>
<property name="creationDate" column="CREATION_DATE" type="timestamp"/>
<property name="lastUpdatedByUserId" column="LAST_UPDATED_BY" type="java.lang.Long"/>
<many-to-one name="rfq"
class="com.cgc.esd.purchasing.RFQ"
column="RFQ_ID" not-null="true"/>
<many-to-one name="rfqSupplier"
class="com.cgc.esd.purchasing.RFQSupplier"
column="SUPL_ID" not-null="true"/>
<bag name="suppliedItems" table="CPO_QUOT_SUPL_ITEMS"
lazy="true" cascade="all-delete-orphan" inverse="true"
outer-join="auto">
<key column="QUOT_ID"/>
<one-to-many class="com.cgc.esd.purchasing.QuotationSuppliedItem"/>
</bag>
</class>
</hibernate-mapping>
[/code]