Though it isn't clear what might have changed with my code or dependencies,
I've started observing strange "caching"-like behavior, even if I disable
the query and data caches. I've changed a few things recently... going to
JDK 1.6, updating to a newer version of Wicket (and along with that its
dependencies), etc. I don't think the problem is related to my updating to
OpenJPA 1.1.0, since I tried downgrading back to 1.0.1 and still saw the
same behaviour.
What I'm doing is pretty simple, so it seems likely I've got the semantics
wrong in some way...
My unit test has a createTestUser in the setUp method which creates a dummy
Account. For the test in question, I need that Account to have the
"verified" boolean field set to false, so the test begins by performing a
query for the dummy Account followed by an update to false. Then if the
code does what it's supposed to do, the field gets set back to true.
The query code looks like this:
final Query q = em.createQuery("select x from Account x where
x.username = ?1");
q.setParameter(1, username);
final Account account = (Account) q.getSingleResult();
And the update code looks like this:
EntityManager em = getEM();
account = find(em, username);
em.getTransaction().begin();
account.setVerified(true);
em.getTransaction().commit();
em.close();
On the last query with a new EntityManager, isVerified() returns false, even
if i do an em.refresh(account). I have verified that on the database, it
actually did get updated to true. I do see OpenJPA actually run a query to
populate the object, and if I run that query by hand, I get the right
data... it just seems like the results of that query are not heeded.
I also see by printing out the identity hashcodes that the last time I
execute the query, I get back the object that was retrieved immediately
after executing the first update (to set the initial value to false), and
the two queries in between each returned a different object. To put it
another way:
Initial object created: 31746664
Object after update to false: 14113863
Object retrieved for update: 5263041
Object retrieved for verification of update: 14113863
Any ideas about what I should look into more deeply, or a setting I should
tweak?
Nick
--
"Courage isn't just a matter of not being frightened, you know. It's being
afraid and doing what you have to do anyway."
-- Doctor Who - Planet of the Daleks
This message has been brought to you by Nick Johnson 2.3b1 and the number 6.
http://healerNick.com/ http://morons.org/ http://spatula.net/