Getting mixed new/old data when refreshing page

i have a web app that reads in objects from the db, allows the users to make changes, inserts, etc. and all that works fine. the problem is, sometimes, the old values of the modified objects appear, and sometimes they do not. if i refresh the page over and over again i can see the new and old values showing up randomly.

the only way to fix this so far has been to redeploy my application to the server. invalidating the users session does not work, i tried using .evict(object), but that didnt work either (maybe im not using it at the right time, i tried using it after the .save(), and the .commit() of the object and the transaction and that had no effect.)

i understand that hibernate does some caching to minimize the amount of queries it executes, but does that explain why the new AND old data are showing up randomly?

Hello Atmospherian,

I will discuss with our engineers and come back to you.

Best regards,
Jick

Hello Atmospherian,

Please answer the following questions:

  1. Which kind of code are you implementing? Java or .NET
  2. Which kind of Persistent API did you choose? (e.g. POJO, Factory, DAO and etc.)
  3. Which kind of WebServer are you using? What version is it?
  4. Which kind of database are you using? (e.g. MySQL, Oracle, MSSQL…).
  5. Which kind of Mapping type (XML/Annotation) did you choose? (for Java orm only)

Is it possible to send us your project file to have a look? If possible, I suggest you send me your project through E-mail. My E-mail address is:
jick@visual-paradigm.com

Best regards,
Jick

Hi Atmospherian,

I have had the same problem as you! I also noticed that “evict” wouldn’t work, and I used to get the absolute same effect as you (having old and new data show up randomly).

This is what helped me:

Whenever I want to change data I follow these steps:

  • save a name or id of the object I want to change, so I can identify it later (for a new object this isn’t necessary)
  • start a new transaction
  • make the changes
  • object.save()
  • commit(), flush()
  • close and reopen the session!
  • reload the object by f.ex. looking up the id or the name and loading it into the session the usual way, so that the object will be reloaded into the hibernate session.

Like I said, evict just doesn’t do what it’s supposed to do. At least for me, whereas I must say that I still might have some configuration problem, as commited and flushed changes aren’t reflected in the database, until I stop my app server (WASCE). But at least I have changes reflected in my web app, by now.

Closing and re-opening the session looks like this:

ProjectNamePersistentManager.instance().getSession().close();
ProjectNamePersistentManager.instance().getSession();

HTH
Christine

Oh, one more thing: Additionally, I guess you should turn off browser caching. I have these lines in my JSP/HTML header:

<meta http-equiv="cache-control" content="no-cache,must-revalidate">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">

[quote=christine.slotty]Oh, one more thing: Additionally, I guess you should turn off browser caching. I have these lines in my JSP/HTML header:

<meta http-equiv="cache-control" content="no-cache,must-revalidate">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">

[/quote]

Hey Christine,

thanks for your replies, i will definitely try out your suggestions and see if they help.

Atmospherian

[quote=Jick]Hello Atmospherian,

Please answer the following questions:

  1. Which kind of code are you implementing? Java or .NET
    Java
  2. Which kind of Persistent API did you choose? (e.g. POJO, Factory, DAO and
    etc.)
    Factory
  3. Which kind of WebServer are you using? What version is it?
    tried with Glassfish v1 and v2 beta, and JBoss 4.0.5 and 4.2
  4. Which kind of database are you using? (e.g. MySQL, Oracle, MSSQL…).
    MySQL 5
  5. Which kind of Mapping type (XML/Annotation) did you choose? (for Java orm only) XML mapping

Is it possible to send us your project file to have a look? If possible, I suggest you send me your project through E-mail. My E-mail address is:
jick@visual-paradigm.com

Best regards,
Jick[/quote]

Hi Atmospherian,

Sorry, I didn’t aware the above post has your reply included. I just spotted and asking our engineers for more details.

Best regards,
Jick

HI Atmospherian,

We guess that you haven’t close the session at the end of the request, which caused the old value to be cached in the old sessions.

Best regards,
Jick