-->
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.  [ 3 posts ] 
Author Message
 Post subject: Old version of object retrieved from cache
PostPosted: Fri Oct 28, 2005 1:50 pm 
Beginner
Beginner

Joined: Fri Oct 28, 2005 12:26 pm
Posts: 21
I'm having a caching problem. I update a record on one page, then access it on the next. When the record is accessed, the updates that were made are not present. I'm now trying to force a re-read from the database, but it's not working. Here's my code.

Code:
TrackingStep rootTracking = (TrackingStep)session.load(
    TrackingStep.class, rootTrackingID, LockMode.READ);


When I run the application, it generates this in the logs.

Code:
Locking entity: [com.idex.processtracking.bean.TrackingStep#21]
about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
select id from TrackingSteps where id =?
preparing statement
binding '21' to parameter: 1
about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
closing statement
resolved object in session cache: [com.idex.processtracking.bean.TrackingStep#21]


The ID refresh is a little pointless ... But it's doing it, then it gets the object from session cache. Does anyone know why this is happening? This isn't the only place I'm having this problem.

Hibernate version: 3.0.5

Mapping documents:
Code:
<hibernate-mapping>
  <class name="com.idex.processtracking.bean.TrackingStep"
      table="TrackingSteps">
    <id column="id" name="id" type="integer">
      <generator class="increment"/>
    </id>
    <many-to-one name="processStep" column="processStepID" not-null="true"
        cascade="save-update" class="com.idex.processtracking.bean.ProcessStep"
        />
    <many-to-one name="parentStep" column="parentStep"
        cascade="all" class="com.idex.processtracking.bean.TrackingStep" />
    <set name="childSteps" inverse="true" cascade="none">
      <key column="parentStep" />
      <one-to-many class="com.idex.processtracking.bean.TrackingStep" />
    </set>
    <many-to-one name="nextStep" column="nextStep" cascade="none"
        class="com.idex.processtracking.bean.TrackingStep" />
    <property name="startTime" column="startTime" type="timestamp"
        not-null="true" />
    <property name="endTime" column="endTime" type="timestamp" />
    <many-to-one name="user" column="userName" cascade="none" not-null="true"
        class="com.idex.processtracking.bean.User" />
    <property name="description" column="description" type="string" />
    <set name="authorizedUsers" lazy="true" inverse="true" cascade="none">
      <key column="trackingID" />
      <one-to-many class="com.idex.processtracking.bean.TrackingUser" />
    </set>
    <set name="textDetails" inverse="true" lazy="true" cascade="all">
      <key column="trackingID" />
      <one-to-many class="com.idex.processtracking.bean.TrackingTextDetail" />
    </set>
  </class>
</hibernate-mapping>


Name and version of the database you are using: SQL Server 2000


Top
 Profile  
 
 Post subject: Anything
PostPosted: Mon Oct 31, 2005 10:23 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 12:26 pm
Posts: 21
Is there, maybe, something extra I have to put in the config file to have Hibernate update more than the ID field (which never changes)?


Top
 Profile  
 
 Post subject: Solved
PostPosted: Mon Oct 31, 2005 1:08 pm 
Beginner
Beginner

Joined: Fri Oct 28, 2005 12:26 pm
Posts: 21
It looks like I solved it. Since I use Struts, I use ThreadLocal variables to hold my sessions and transactions. Since Tomcat starts multiple threads, each one gets its own Hibernate session and keeps its own cache. I did not want to disable caching or clear the cache at the beginning of each request and I was tearing my hair out trying to find the setting. I finally found this. It has a tiny little section about ThreadLocal. I just had to add this to my Hibernate config.

Code:
<property name="current_session_context_class">thread</property>


I award all points to me. Or ... I would.


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