-->
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.  [ 1 post ] 
Author Message
 Post subject: Serialize uninitialized intrumented classes and a patch
PostPosted: Tue Jan 16, 2007 1:52 pm 
Newbie

Joined: Fri Dec 17, 2004 2:38 pm
Posts: 11
Location: Buenos Aires
Hi people!

I've a problem with Javassist Instrumented clases (I mean, classes instrumented with the javassist InstrumentTask ).

After serialize and deserialize my entity and make a session.lock(), all my lazy properties are null.

After some debugging I think I've found the problem. The property created in the enhaced class where hibernate put the FieldInterceptor used for initialize the class is transient.

Then, After deserialize the class and make a session.lock(), hibernate create a new FieldInterceptor instead using the one created before(see AbstractEntityPersister.afterReassociate(..)) , but with the property 'uninitializedFields' in null. So, my unitialized properties return null.

I changed the class FieldTransformer so, the property now is only private. Then all works like a charm

I don't know if it is a bug or I've misunderstand something. this is the patch (against the v321 tag in svn). I can reproduce the same with cglib, but I haven't fix it. If it's necessary, I think I can do it.

I haven't make an issue because I don't know if it is a bug.

Code:
Index: Hibernate3/src/org/hibernate/bytecode/javassist/FieldTransformer.java
===================================================================
--- Hibernate3/src/org/hibernate/bytecode/javassist/FieldTransformer.java   (revision 11045)
+++ Hibernate3/src/org/hibernate/bytecode/javassist/FieldTransformer.java   (working copy)
@@ -111,7 +111,7 @@
      ConstPool cp = classfile.getConstPool();
      FieldInfo finfo = new FieldInfo(cp, HANDLER_FIELD_NAME,
                                      HANDLER_FIELD_DESCRIPTOR);
-      finfo.setAccessFlags(AccessFlag.PRIVATE | AccessFlag.TRANSIENT);
+      finfo.setAccessFlags(AccessFlag.PRIVATE);
      classfile.addField(finfo);
   }




And this is my test case

Code:
      Tracker t=<find the tracker with a hql>
      assertFalse(Hibernate.isPropertyInitialized(t, "businessData"));
      assertTrue(Hibernate.isPropertyInitialized(t, "id"));
      
      t= (Tracker) SerializationHelper.clone( t );
      session.flush();
      session.clear();
      
      session.lock(t,LockMode.NONE);
      
      assertFalse(Hibernate.isPropertyInitialized(t, "businessData"));
      assertTrue(Hibernate.isPropertyInitialized(t, "id"));


And the mapping

Code:

<?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 default-lazy="true" >
   <class name="Tracker"
      schema="tracker"
      table="TRACKER_ENTITY">
         
      <composite-id name="id" class="Tracker$Id">
         <key-property name="id"  column="ID" length="32"/>
         <key-property name="year" column="YEAR_PART"/>
         <key-property name="control" column="CONTROL_PART" />
      </composite-id>

      <version name="version" type="long" unsaved-value="null"/>
   
   
      <map
         name="otherValues"
         schema="tracker"
         table="TRACKER_VALUES"
         cascade="all-delete-orphan" lazy="true" fetch="select">
         <key>
            <column name="ID_TRACKER"/>
            <column name="YEAR_PART"/>
            <column name="CONTROL_PART"/>
         </key>
         <map-key column="NAME" type="string"/>
         <element type="extension.hibernate.DynamicPrimitiveType">
            <column name="VALUE"/>
            <column name="TYPE"/>         
         </element>
      </map>

      <many-to-one
         name="status"
         column="ID_STATUS"
         class="TrackerStatus"
         fetch="select"
         lazy="false"
      />
      
      <dynamic-component name="keyValues">
         <!-- numeric slots -->
         <property name="N1" type="big_decimal"/>
         <property name="N2" type="big_decimal"/>
         <property name="N3" type="big_decimal"/>
         <property name="N4" type="big_decimal"/>
         <property name="N5" type="big_decimal"/>
         <!-- text slots -->
         <property name="C1" type="string"/>
         <property name="C2" type="string"/>
         <!-- date slots -->
         <property name="D1" type="java.util.Date"/>
         <property name="D2" type="java.util.Date"/>
         <!-- boolean slots -->
         <property name="B1" type="boolean"/>
         <property name="B2" type="boolean"/>
      </dynamic-component>
      
      <component
         name="businessData"
         class="BusinessData"
         lazy="true"
         update="false">
         <many-to-one
            name="party" fetch="select" update="false" cascade="none" not-null="true"
            class="Party"
            column="ID_PARTY"
         />
         <property name="partyPartner" column="PARTY_PARTNER" type="int"/>
         <component
            name="validPeriod"
            class="Period">
            <property name="value" column="VALID_PERIOD"/>
         </component>
         <property name="advanceQuotePayment" column="ADVANCE_QUOTE_PAYMENT" type="int" />
         <many-to-one
            name="product"
            column="ID_PRODUCT"
            class="Product"
            not-null="true"
            fetch="select"/>
         <property name="bookCode" column="BOOK_CODE" type="int" />
         <property name="conceptCode" column="CONCEPT_CODE" type="int" />      
         <property name="generalExpirationDate" column="EXPIRATION" type="extension.hibernate.InstantType" />
      </component>
      <property name="whenLastCharged" column="WHEN_LASTCHARGED" type="extension.hibernate.InstantType" />
      <property name="whenLastBooked" column="WHEN_LASTBOOKED" type="extension.hibernate.InstantType" />
      <property name="whenCharged" column="WHEN_CHARGED" type="extension.hibernate.InstantType" />
      <property name="whenBooked" column="WHEN_BOOKED" type="extension.hibernate.InstantType" />
      <property name="voucherID" column="ID_ORDER"/>
      <property name="lastVoucherID" column="ID_LASTORDER"/>

   </class>
</hibernate-mapping>




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

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.