-->
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.  [ 8 posts ] 
Author Message
 Post subject: transient error when using JCS
PostPosted: Thu Sep 04, 2003 4:36 pm 
Newbie

Joined: Wed Aug 27, 2003 2:53 pm
Posts: 14
Location: New Jersey
I'm trying to add JCS caching to my application and I'm running into the following "transient instance" error when I retrieve objects through the cache:
Quote:
object references an unsaved transient instance - save the transient instance before flushing


The rough logic of my code is as follows:

* create new hibernate session
* retrieve data (loading all objects for class T1), loading into the cache
* close hibernate session

* open new hibernate session
* retrieve data (loading all objects for class T1), using the cache if possible
* close hibernate session

The first hibernate session logic works fine. With debugging turned on for the hibernate.cache package, I see statements that my objects are being added to the cache.

The second hibernate session logic is where problems occur. With debugging turned on for the hibernate.cache package, I see statements that my objects are being loaded from the cache (cache hits), but then I get the transient error.

The JCS caching that I have set-up includes both nonstrict-read-write and read-only usages. Class T1 is set-up to be nonstrict-read-write. It contains a key-many-to-one property (Class T2) that is also configured as a nonstrict-read-write cache. Class T2 contains a key-many-to-one property (Class T3) that is configured as a read-only cache (because it is static data). It is in processing an object of type T3 that I get this error.

Since my mappings represent a complex object graph and my application is quite large at this point, I am not including the specifics here. I was hoping I could get some clarification on what may be happening.

The exception is thrown from SessionImp.getEntityIdentifierIfNotUnsaved(). I use interceptors to determine if an object is a new instance or not, and the logic of getEntityIdentifierIfNotSaved() accesses my interceptor code. My interceptor code indicates that the object's isUnsaved value is true. But I don't understand why, since it was cached from a previous load from the database. My interceptor sets a "saved" property to true when onLoad() or onSave() is called. Is a copy of my persistent object from the cache being made without the benefit of the onLoad() semantics so that my "saved" property is not being set?

Any thoughts? Thanks in advance.

Sarah


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 10:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
An object is cached in a "disassembled" form. ie. it is not the same instance you get back out of the cace that you put into it.

Now, I just noticed that, whereas Lifecycle.onLoad() is called even when we pull something from the cache, Interceptor.onLoad() is not currently being called in this case. This is almost an actual bug, I think.

But, assuming you are initializing the isUnsaved value in Interceptor.onLoad(), this would explian your problem.

Use Lifecycle.onLoad() instead, as a workaround.


I'll fix this.


Top
 Profile  
 
 Post subject: "Disassembled" objects
PostPosted: Fri Sep 05, 2003 11:39 am 
Newbie

Joined: Wed Aug 27, 2003 2:53 pm
Posts: 14
Location: New Jersey
Thanks Gavin, using the lifecycle interface does cause my transient problem to go away.

I have a follow-up question related to caching of objects. I have a class OrganizationRole that has 3 one-to-many collections that are NOT lazy loaded. When I get a cache hit for an OrganizationRole object, hibernate still seems to be executing queries against the database to retrieve the collections. I have these collections configured to use caching as well. Shouldn't it be getting the collections from the cache as well?

---------------------------------------------------------------------

Here is my mapping for OrganizationRole:
Quote:
<class name="org.ets.k12.generic.domain.OrganizationRole" table="ORG_RLE">
<jcs-cache usage="nonstrict-read-write"/>
<composite-id unsaved-value="any">
<key-many-to-one name="organization" column name="ORG_ID_NO" class="org.ets.k12.generic.domain.Organization"/>
<key-many-to-one name="orgRoleType" column="ORG_RLE_TYP_CDE" class="org.ets.k12.generic.domain.OrganizationRoleType"/>
</composite-id>

<many-to-one name="aiType" column="AI_TYP_CDE" class="org.ets.k12.generic.domain.AIType"/>
<many-to-one name="orgExtType" column="ORG_EXTRNL_TYP_CDE" class="org.ets.k12.generic.domain.OrganizationExternalType"/>
<property name="lastUpdated" column="UPDT_DTE_TM" type="java.sql.Timestamp"/>
<property name="lastUpdatedBy" column="UPDT_USR_LGN_CDE" type="java.lang.String"/>

<set name="orgRoleTestAdmins" lazy="false" inverse="true" cascade="all">
<jcs-cache usage="nonstrict-read-write"/>
<key>
<column name="ORG_ID_NO"/>
<column name="ORG_RLE_TYP_CDE"/>
</key>
<one-to-many class="org.ets.k12.generic.domain.OrganizationRoleTestAdministration"/>
</set>

<set name="orgRoleAddresses" lazy="false" inverse="true" cascade="all">
<jcs-cache usage="nonstrict-read-write"/>
<key>
<column name="ORG_ID_NO"/>
<column name="ORG_RLE_TYP_CDE"/>
</key>
<one-to-many class="org.ets.k12.generic.domain.OrganizationRoleAddress"/>
</set>


<set name="aiGradeLevel" lazy="false" inverse="true" cascade="all">
<jcs-cache usage="nonstrict-read-write"/>
<key>
<column name="ORG_ID_NO"/>
<column name="ORG_RLE_TYP_CDE"/>
</key>
<one-to-many class="org.ets.k12.generic.domain.AIGradeLevel"/>
</set>
</class>


---------------------------------------------------------------------

Here's the output I see when I have debugging turned on for the hibernate.cache package.

Quote:
[9/5/03 11:32:59:660 EDT] 6608851f SystemOut U 2003-09-05 11:32:59,539 DEBUG [Thread-12] cache.NonstrictReadWriteCache:22 - Cache hit: 20000

[9/5/03 11:29:41:244 EDT] 6608851f SystemOut U 2003-09-05 11:29:41,184 DEBUG [Thread-12] cache.ReadOnlyCache:22 - Cache hit: CT

[9/5/03 11:29:41:304 EDT] 6608851f SystemOut U 2003-09-05 11:29:41,244 DEBUG [Thread-12] cache.NonstrictReadWriteCache:22 - Cache hit: org.ets.k12.generic.domain.OrganizationRole@89ca917b

[9/5/03 11:29:41:304 EDT] 6608851f SystemOut U Hibernate: select org_rle_0_.TST_ADM_MO_NO as TST_ADM_1___, org_rle_0_.TST_ADM_YR_NO as TST_ADM_2___, org_rle_0_.ORG_ID_NO as ORG_ID_NO__, org_rle_0_.ORG_RLE_TYP_CDE as ORG_RLE_4___, organiza1_.ORG_EXTRNL_TYP_CDE as ORG_EXTRNL_TYP_CDE0_, organiza1_.ORG_EXTRNL_TYP_DESC as ORG_EXTR2_0_, org_rle_0_.TST_ADM_MO_NO as TST_ADM_MO_NO1_, org_rle_0_.TST_ADM_YR_NO as TST_ADM_YR_NO1_, org_rle_0_.ORG_ID_NO as ORG_ID_NO1_, org_rle_0_.ORG_RLE_TYP_CDE as ORG_RLE_TYP_CDE1_, org_rle_0_.ORG_EXTRNL_TYP_CDE as ORG_EXTR5_1_, org_rle_0_.INDPNT_CHTR_SCHL_FLG as INDPNT_C6_1_, org_rle_0_.ORG_RLE_TST_ADM_AFDVT_FLG as ORG_RLE_7_1_, org_rle_0_.ORG_RLE_TST_ADM_LT_TST_FLG as ORG_RLE_8_1_, org_rle_0_.ORG_RLE_TST_ADM_PO_NO as ORG_RLE_9_1_, org_rle_0_.UPDT_DTE_TM as UPDT_DT10_1_, org_rle_0_.UPDT_USR_LGN_CDE as UPDT_US11_1_ from ORG_RLE_TST_ADM org_rle_0_, ORG_EXTRNL_TYP organiza1_ where org_rle_0_.ORG_ID_NO=? and org_rle_0_.ORG_RLE_TYP_CDE=? and org_rle_0_.ORG_EXTRNL_TYP_CDE=organiza1_.ORG_EXTRNL_TYP_CDE(+)
[9/5/03 11:29:41:384 EDT] 6608851f SystemOut U 2003-09-05 11:29:41,324 DEBUG [Thread-12] cache.NonstrictReadWriteCache:46 - Caching invalidated: org.ets.k12.generic.domain.OrganizationRole@89ca917b

[9/5/03 11:29:41:384 EDT] 6608851f SystemOut U Hibernate: select org_rle_0_.ORG_ID_NO as ORG_ID_NO__, org_rle_0_.ORG_RLE_TYP_CDE as ORG_RLE_2___, org_rle_0_.ADR_ID_NO as ADR_ID_NO__, addressp1_.ADR_TYP_ID_NO as ADR_TYP_ID_NO0_, addressp1_.ADR_PRPS_TYP_ID_NO as ADR_PRPS_TYP_ID_NO0_, addressp1_.ADR_PRPS_TYP_DESC as ADR_PRPS3_0_, org_rle_0_.ORG_ID_NO as ORG_ID_NO1_, org_rle_0_.ORG_RLE_TYP_CDE as ORG_RLE_TYP_CDE1_, org_rle_0_.ADR_ID_NO as ADR_ID_NO1_, org_rle_0_.ADR_TYP_ID_NO as ADR_TYP_4_1_, org_rle_0_.ADR_PRPS_TYP_ID_NO as ADR_PRPS5_1_, org_rle_0_.UPDT_DTE_TM as UPDT_DTE6_1_, org_rle_0_.UPDT_USR_LGN_CDE as UPDT_USR7_1_, org_rle_0_.ORG_RLE_ADR_EFF_DTE as ORG_RLE_8_1_, org_rle_0_.ORG_RLE_ADR_EXPRTN_DTE as ORG_RLE_9_1_ from ORG_RLE_ADR org_rle_0_, ADR_PRPS_TYP addressp1_ where org_rle_0_.ORG_ID_NO=? and org_rle_0_.ORG_RLE_TYP_CDE=? and org_rle_0_.ADR_TYP_ID_NO=addressp1_.ADR_TYP_ID_NO(+) and org_rle_0_.ADR_PRPS_TYP_ID_NO=addressp1_.ADR_PRPS_TYP_ID_NO(+)
[9/5/03 11:29:41:464 EDT] 6608851f SystemOut U 2003-09-05 11:29:41,404 DEBUG [Thread-12] cache.NonstrictReadWriteCache:46 - Caching invalidated: org.ets.k12.generic.domain.OrganizationRole@89ca917b

[9/5/03 11:29:41:464 EDT] 6608851f SystemOut U Hibernate: select ai_grd_l0_.ORG_ID_NO as ORG_ID_NO__, ai_grd_l0_.ORG_RLE_TYP_CDE as ORG_RLE_2___, ai_grd_l0_.GRD_LVL_TYP_CDE as GRD_LVL_3___, ai_grd_l0_.ORG_ID_NO as ORG_ID_NO, ai_grd_l0_.ORG_RLE_TYP_CDE as ORG_RLE_TYP_CDE, ai_grd_l0_.GRD_LVL_TYP_CDE as GRD_LVL_TYP_CDE, ai_grd_l0_.AI_GRD_LVL_EFF_DTE as AI_GRD_L4_, ai_grd_l0_.AI_GRD_LVL_EXPRTN_DTE as AI_GRD_L5_, ai_grd_l0_.UPDT_DTE_TM as UPDT_DTE6_, ai_grd_l0_.UPDT_USR_LGN_CDE as UPDT_USR7_ from AI_GRD_LVL ai_grd_l0_ where ai_grd_l0_.ORG_ID_NO=? and ai_grd_l0_.ORG_RLE_TYP_CDE=?
[9/5/03 11:29:41:545 EDT] 6608851f SystemOut U 2003-09-05 11:29:41,474 DEBUG [Thread-12] cache.NonstrictReadWriteCache:46 - Caching invalidated: org.ets.k12.generic.domain.OrganizationRole@89ca917b


The cache hit of "20000" is for Organization and the cache hit of "CT" is for OrganizationRoleType.

One other thing I notice, is that I get "Caching invalidated ..." and "Invalidating ..." debug statements for the OrganizationRole cached objects. I don't get those messages for other objects that are cached. Can you explain this?

Thanks alot!

Sarah


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 9:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The "Caching Invalidated" message means that last time we touched the cache it was twhile we were modifying the collection. Which also fully explains the fact that we hit the database.

Check that you aren't unnecessarily updating collections.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 08, 2003 11:43 am 
Newbie

Joined: Wed Aug 27, 2003 2:53 pm
Posts: 14
Location: New Jersey
I've tried to figure out if I'm updating the collections and as far as I can tell, I am not. I've put breakpoints in my interceptor code for onFlushDirty(), onSave() and onUpdate(). None of them are being hit. In addition, all my code is doing is retrieving the data and caching it according to some business logic. It then reloads the data at a fixed time interval (this is just for my testing purposes).

Is there any other way to know where/how the collections are being updated?

Thanks,
Sarah


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 08, 2003 11:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Add a <version> column to your mapping for the collection owner. Then onFlushDirty() will be called when a collection is updated.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2003 2:15 pm 
Newbie

Joined: Wed Aug 27, 2003 2:53 pm
Posts: 14
Location: New Jersey
I have added the <version> property to the class that contains the collections, but still my interceptor onFlushDirty() method is not being called.

Additionally, if I turn trace level debugging on for the hibernate.cache package and the hibernate.imp.SessionImpl class, the behavior changes . . . hibernate does not invalidate my JCS cache entries like it does when I don't have trace debugging enabled.

Any other ideas as how I might track down this problem?

Thanks,
Sarah


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2003 2:51 pm 
Newbie

Joined: Wed Aug 27, 2003 2:53 pm
Posts: 14
Location: New Jersey
Please ignore my most recent post in this thread. It seems that the application commit logic we had was broken. Now that our application's commit logic has changed, the cache invalidating debug statements don't appear any more.

Thanks for your help!

Sarah


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.