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?
Which kind of code are you implementing? Java or .NET
Which kind of Persistent API did you choose? (e.g. POJO, Factory, DAO and etc.)
Which kind of WebServer are you using? What version is it?
Which kind of database are you using? (e.g. MySQL, Oracle, MSSQL…).
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
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:
Which kind of code are you implementing? Java or .NET
Java
Which kind of Persistent API did you choose? (e.g. POJO, Factory, DAO and
etc.)
Factory
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
Which kind of database are you using? (e.g. MySQL, Oracle, MSSQL…).
MySQL 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