The Best Damn Visual Studio Add-In Ever

Java JPA Doesn’t Show Updates to tables

15. September 2011 17:21 by Scott in   //  Tags: , , ,   //   Comments (27)

There was a problem one of my peers found with Java JPA that got him stuck for a few hours.  He told me to blog about it so here it is.

When you use the JAVA JPA library.  You will pull results from the database.  That’s exactly what the JPA lib does.  Its like LINQ, but for Java.

So here is the problem.  When pulling results from the JPA objects from the database, the JPA then caches all the objects.  So every time after that, the cached results get returned instead of the most important information just placed in the Database.  So, in order to get around this, you must call the “refresh” method.  Or at least that’s what he told me to say.  That method will then hit the DB again for another round trip and update all the objects on the JPA side.

That is all.