curious "caching" behaviour

3 messages Options
Embed this post
Permalink
Nick Johnson-15

curious "caching" behaviour

Reply Threaded More More options
Print post
Permalink
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/
Nick Johnson-15

Re: curious "caching" behaviour

Reply Threaded More More options
Print post
Permalink
I kept digging and found the answer to my problem.  The kicker was my move
to Eclipse Ganymede and loss of my previous running configurations that
included the -javaagent for instrumenting my classes before the unit tests
ran.  It probably mattered because Account has a lazy 1:1 reference to
itself, and my test indirectly updated that lazy reference.

This might have been combined with moving to Java 1.6 as well, since the
chapter on enhancement suggests that OpenJPA tries to cope with having no
enhancer in Java 1.6 by using runtime class retransformation.

I've already uninstalled Java 1.5 off my system, or I'd try my test on 1.5
with no javaagent to see if the behaviour is specific to 1.6.  It's
plausible that there -could- be a problem with class retransformation.

   Nick

2008/7/27 Nicklas Johnson <[hidden email]>

> 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.
> [snip]
>



--
"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/
Frederic_Bellier

Re: curious "caching" behaviour

Reply Threaded More More options
Print post
Permalink
In reply to this post by Nick Johnson-15
Are you the Nicklas Johnson that once was in A'dam? (CTP)

Frederic




                                                                           
             "Nicklas Johnson"                                            
             <[hidden email]                                            
             et>                                                        To
                                       [hidden email]            
             Sent by:                                                   cc
             [hidden email]                                            
             et                                                    Subject
                                       curious "caching" behaviour        
                                                                           
             07/27/2008 08:15                                              
             PM                                                            
                                                                           
                                                                           
             Please respond to                                            
             [hidden email]                                            
                  che.org                                                  
                                                                           
                                                                           




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/