-->
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.  [ 7 posts ] 
Author Message
 Post subject: old data shows up on screen after successful update
PostPosted: Thu Apr 01, 2004 9:56 am 
Newbie

Joined: Tue Mar 09, 2004 8:58 am
Posts: 15
Hi,
We have some data that is updated to a table from a web-page, the updates are correctly reflected in the database, but when the page is reloaded, some old values show up on the screen.

Interestingly there is a strange pattern, on clicking on the update button repeatedly without modifying the data the previous value(value before the first update) shows up every 5th time.
When the same is done with different data each time, the data shown up on the screen is one amongst the last 5 updates.

Presume this has something to do with the way the data is cached. But we have not done anything to enable caching.

The hibernate mappings are straight and simple with no mapping dependency to any other table.

The mapping-
Code:
<hibernate-mapping>
  <class name="com.ReferralRow" table="REFERRAL">
    <id name="refUid" column="REF_UID" type="long">
   <generator class="sequence">
   <param name="sequence">REF_SEQ</param>
      </generator>
    </id>
   <property name="optionUid" column="OPTION_UID" type="long"/>
......
..... more independent fields
.....


The update code is as follows-
Code:
Session session = HibernateSession.currentSession();
ReferralRow referral = (ReferralRow)session.load(ReferralRow.class,new Long(iRefNo));
referral.setOptionUid(someValue);
set some other fields ...
session.flush();


After update, the retrieve often shows up old values on screen.
Code:
Session session = HibernateSession.currentSession();
List list = session.find("from referral in class com.ReferralRow where referral.optionUid= ?", new Long(optionUid), Hibernate.LONG);
...
set values into a VO..
session.flush();



We're passing a connection object fetched from a connection-pool to Hibernate. Both the update and the fetch happen within the same transaction.

Is there something fundamentally wrong with the code? Why could the old data show up on screen at regular intervals?

-Thanks in adv.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 12:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Sounds like it's not related to Hibernate

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 2:02 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i think it is related to the way you manage the hibernate session.
This can occur if your servlet use a dirty session, to avoid this please search about "open session in view" in hibernate site.


Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 2:54 pm 
Newbie

Joined: Tue Mar 09, 2004 8:58 am
Posts: 15
Our framework is thus-
Struts ->Action->EJB->Data Access
Can I still use the "open session in view" pattern?

We currently use the ThreadLocal pattern which checks for an open session object before fetching another. Isn't this sufficient? From what we saw in the "Open Session in View pattern" we figure the same is done there.

We're doing an intermediate session.flush(); once after the saveOrUpdate and once after the fetch, could this be a problem?

-Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 3:38 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 3:09 pm
Posts: 58
Ae you removing the session from the thread local at the end of the request? If not, you'll get an old session when the servlet container reuses that thread.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 4:45 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you need to
1- close
2- "remove" session from thread (on each request is the most secure)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 2:05 am 
Newbie

Joined: Tue Mar 09, 2004 8:58 am
Posts: 15
We are closing the session and setting the ThreadLocal object to null at the end of the request.
In this particular case, the save and fetch are being done within the same request, so the session is not closed in between the save and fetch.

This is what we were doing-
I- For every transaction/request-
a) perform database operations( as described in II below)
b) close connection
c) set the ThreadLocal object to null
d) close the session

II- For every database operation -
a) getSession
b) perform db operation
c) flush

Now, if we close the session after the save and open it again for the fetch, it works fine, but I wonder if this is the right way to do it.
If we close the session and set the ThreadLocal object to null after the save, wouldn't we end up committing the data to the database, but we don't want to be committing until the transaction/request is complete.


We rely on the EJB container for transaction management. The database connection is also received from the app-server's connection pool.


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