开发者

Java EclipseLink persistence library incorrect data returned

I'm using the EclipseLink provider to talk to a mysql database. I've noticed that in on area of my application the library is returning query data that doesn't match the DB.

The query is:

@NamedQuery(name = "EmailAddress.findAll", query = "SELECT e FROM EmailAddress e")

This query is correct, I'm certain of that. The code that I'm using to run that query is:

  EntityTransaction entr = em.getTransaction();
  entr.begin();
  emailAddresses = em.createNamedQuery("EmailAddress.findAll").getResultList();
  em.close()

I've put a breakpoint on the close so that I can see the contents of the emailAddress list, about 1 time in 3 it the array is populated incorrectly. A bit more background - I have a table that lists names, clicking on a name pops up a dialogue and allows you to change the name, upon clicking save it closes the dialogue and updates the table (both DB and UI), sometimes the UI is incorrectly updated and the editted name d开发者_Go百科oes not update. The update runs code including that above block. The database is correctly updated prior to the code being run, it's just that array is not populated correctly.

Has anybody else had any issues related to this or have any ideas?

Any help much appreciated!


I fixed this by making the cache refresh on every query, so it was something with the cache. As this app is single user and not very big there aren't many DB hits so this is fine for this application.


Difficult to say without seeing the rest of the code, but are you sure that:

  1. Your transactions are not long winded (i.e. you don't open a transaction and keep it open while waiting for the user is doing something). You should open and close transactions around data queries/updates only.

  2. You are calling persist(), merge() and refresh() respectively when you are creating or updating entities.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜