-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Exception writing persisted object with XMLEncoder
PostPosted: Wed Jan 21, 2004 1:50 am 
Newbie

Joined: Wed Aug 27, 2003 2:23 am
Posts: 5
Location: Lahore, Pakistan
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]


Top
 Profile  
 
 Post subject: Re:
PostPosted: Wed Jan 21, 2004 2:07 am 
Newbie

Joined: Thu Sep 18, 2003 1:50 am
Posts: 17
Remove the proxy attribute of the class.

_________________
- Jeevan (G1)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 4:25 am 
Newbie

Joined: Thu Nov 27, 2003 4:50 am
Posts: 16
Location: M
I tried to serialize a hibernate-persistent Class with the java.beans.XMLEncoder and i get the folowing errors:

java.lang.IllegalAccessException: Class java.beans.Statement can not access a member of class net.sf.hibernate.impl.SessionImpl$CollectionEntry with modifiers ""
Continuing ...
java.lang.RuntimeException: failed to evaluate: <unbound>=SessionImpl$CollectionEntry.new();
Continuing ...
java.lang.IllegalAccessException: Class java.beans.Statement can not access a member of class net.sf.hibernate.impl.SessionImpl$CollectionEntry with modifiers ""
Continuing ...
java.lang.RuntimeException: failed to evaluate: <unbound>=SessionImpl$CollectionEntry.new();
Continuing ...
java.lang.IllegalAccessException: Class java.beans.Statement can not access a member of class net.sf.hibernate.impl.SessionImpl$CollectionEntry with modifiers ""
Continuing ...
java.lang.RuntimeException: failed to evaluate: <unbound>=SessionImpl$CollectionEntry.new();
Continuing ...


Any hints?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 21, 2004 5:47 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 2:06 am
Posts: 33
I am also facing the same problem. Can u guys help me out how u solved the problem. I am keeping the session open... still i get an exception


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.