I have a situation where I check to see if the user's login is still valid. This check is a simple database check of a date field.
What I'm noticing is that if I change the value in the database, the hibernate code doesn't always "see" the new value and says that the user's account has expired when, in fact, I just updated it and saved the results (separately, in MYSQL).
I've tried clearing the browser cache and using session.flush() on the hibernate logic, but neither of these things seems to fix the fact that the hibernate code is not getting the current DB value.
Is there another way to make sure I'm getting the most current database data?
There are a few places this could happen. your session handling could be suspect - can you show use the code you use to get the latest data from the db? Usually, opeing a new session and calling a get method will read the database. If you are reusing a session you may get cached data. Are you using a second level cache or query cache?
What I'm noticing is that if I change the value in the database, the hibernate code doesn't always "see" the new value and says that the user's account has expired when, in fact, I just updated it and saved the results (separately, in MYSQL).
I don't know MySQL very well, but does your SQL client auto-commit? I.e. have you really updated the data or does it just appear you have?
Once I re-start Tomcat, all is OK again.
This is authentication code, right? Tomcat (like most containers) has an authentication cache (because reauthenticating for every call is drag on performance). Depending on what you are doing and how you are doing it you may be hitting this.
1. The code that I'm using references boilerplate code that MyEclipse creates for you automatically. I didn't hand-craft the underlying session code or anything like that. And,....
2. This code works perfectly locally.
Both local and remote (server) the code is using Tomcat 5.5, MySQL 5.0.x (though different actual release numbers). Remote uses Apache and Linux where development is Windows and just Tomcat for both Web server and servlet container. Both local and remote use the same JDBC driver version (though I also tried the 3.x and 5.0 versions on the server to see if that would help. It didn't).
I also tried adding autoReconnect="true" as shown below (from hibernate config file), but that didn't seem to help either...