Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Force query to db and not use cache

Ok, I realized I didn't look at my log close enough.

I had tried this:

query.setHint(QueryHints.CACHE_USAGE, CacheUsage.DoNotCheckCache);

and I tried your suggestion as well.

Both have the same result. My query does show the sql, so it seems like it
is going to the database, but it doesn't seem to pick up a new object.

Basically, before, it looked like it wasn't even trying to query anything,
no sql statement showed up in my logs. With the query hint, there is a
query, but after the query I print out the object in my log to check the
result, and the value I had manually changed in the database, isn't correct. 

Here is my code:

logger.debug("Getting customer...");
Customer customer = customerService.getCustomer(customerId);
logger.debug("Done getting customer...");
logger.debug("Customer: " + customer);

Before I put in the query hint, on the first call of the struts2 action
which the lines above are in, there is a query between the Getting and Done
getting statements. On the second call, there is nothing.

After I put in the query hint, there is an sql statement between the two,
but when I print out the customer object, even though I changed a value in
the database, it doesn't seem to be picked up, even though it looks like it
returns to the database.

Michael Bar-Sinai wrote:
> I have no experience with spring, but this works in JEE5:
> public class JpaUtils {
>     /**
>      * Makes q ignore the cache.
>      * @param q the query that has to go straight to the DB.
>      * @return q the query that will go to the db now
>      */
>     public static Query noCache( Query q ) {
>         // /!\ Eclipselink specific. Should make the em go straight to the
> DB.
>         q.setHint("org.eclipse.persistence.config.CacheUsage",
> "DoNotCheckCache");
>         return q;
>     }
> }
> On Mon, May 31, 2010 at 8:26 AM, Stephiems <stephanie@xxxxxxxxxxxxxx>
> wrote:
>> I've done a search through this forum and tried just about everything
>> I've
>> found on here from query hints to the cache annotation and properties in
>> the
>> persistence.xml file and I cannot force a particular entity to go to the
>> database every time.
>> I have a table that is updated by an outside source every day, and I want
>> to
>> force going to the database everytime to pick up any changes. No matter
>> what
>> I do it doesn't go to the database the second time.
>> I'm wondering if it is the transaction, or possibly the fact I'm using
>> spring, that is causing it. Anyone else have this issue?
>> Cheers,
>> Stephanie
>> --
>> View this message in context:
>> Sent from the EclipseLink - Users mailing list archive at
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx

View this message in context:
Sent from the EclipseLink - Users mailing list archive at

Back to the top