Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA update not available to some successive queries

 
Glenn Puckett
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Java EE application that runs in the Web Container on JBoss using mySQL. The entire application utilizes JPA for all database access. I'm not even sure how to do a search that will find the problem I am having, although it has to be fairly common.

In a nutshell I have a module that performs an update of an existing table entry. In my debugging I find that if I manually check on mySQL the entry is definitely updated. Following that update I reload a page that determines what to display based on the field I just updated. It DOES reflect the database change. Next I bring up a page that also depends on the new table value and it reflects the PRIOR value of that table entry. Using Eclipse in debug mode I find that when it checks the value of the field it does have the prior value. The only thing I can think of is that JPA/JBoss has cached the original table object and does not refresh it's content after the update is committed. I've been unable to find anything in my searches that even speaks of this except for one entry on this forum that was never commented on. I hope someone will help me with this one.

First here is the code that performs the update


And here is the update code (I get the update successful message in the log)


The following code is run in the next action



As you can see, the code sets the status to STATUS_ACTIVE (1) on the update. Then it checks for STATUS_PENDING (9) on the following action. The original value of the status field was 9. About 70% of the time acctTbl.getStatus() will return STATUS_PENDING (9) (even though the live database reflects the new value) and I get the error message on that page. Occasionally the process works fine and I get a successful completion. If I restart JBoss the new values are reflected every time.

What am I doing wrong? How can I fix it? I am desperate for an answer here.

I appreciate any suggestions.

Thanks.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What JPA provider are you using? What type of caching are you using?
 
Glenn Puckett
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Sutherland wrote:What JPA provider are you using? What type of caching are you using?


Until now I have always coded using JDBC. This is my first adventure into JPA. If I could I'd go back but I am too far into JPA at this point. I am using Hibernate 3.3. I really don't know how the caching is configured. I just let it use defaults.

It appears that if I move the read to the table out of the transaction the update will behave as I expect. But that eliminates the idea of a transaction if I have multiple entries that I need to update.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic