Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] QueryHints Issue !!!

Hello Vaidya,

There is no point keeping the shared cache if you always plan to refresh, as it requires work to keep updated with each transaction commit. So if you are going to constantly refresh, you might as well disable the shared cache and save some merge processing from occurring. If you are only need to refresh occasionally, then there might still be some value to having the shared cache and using cache invalidation instead.

http://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching
has a starter explanation on caching in JPA, and http://wiki.eclipse.org/Introduction_to_Cache_%28ELUG%29 on the overall caches in EclipseLink. The UnitOfWork in the second link relates pretty much to the cache within an EntityManager, while the serverSession cache would be considered the second level cache.

When you specify "eclipselink.cache.shared.default" value="false", you are disabling the second level, serversession cache. This means that when you obtain an EntityManager, all reads will be forced to go to the database to build your entities. JPA though requires that the EntityManager cache them; this is a first level cache both to maintain object identity and to track any changes to them. I do not believe you really want to remove this cache do you? EntityManager provides the clear() method, and the EntityManager itself is meant to represent transactions - they are not usually kept around indefinitely and instead obtained as needed. Clearing or obtaining a new EntityManager with the shared cache off will force the next query for an entity to build it from the database.

While Refresh maybe what you are after as it will pull in the data from the database to refresh both cache levels. But if you disable the shared cache (or use invalidation or other strategies effectively) and manage the EntityManager instance and its cache, you can probably avoid having to always use a refresh.


On 19/09/2012 4:42 PM, vaidya nathan wrote:
So between the following approaches

1. Approach 1. Introduce this in the jpaPropertyMap in the springs
applicationContext.xml
<entry key="eclipselink.cache.shared.default" value="false"/>
and
2. Query jpaq = JpaHelper.createQuery(query, getEntityManager()) ;
  jpaq.setHint(QueryHints.REFRESH, HintValues.TRUE) ;

which is the recommended approach to disable caching totally , so that
all reads/writes go and hit the database and eclipselink doesnt cache
anything..

I see this link from
http://stackoverflow.com/questions/2809275/disable-caching-in-jpa-eclipselink
wherein they had to do both..

Cheers
Vaidya



On Tue, Sep 18, 2012 at 3:19 PM, Christopher Delahunt
<christopher.delahunt@xxxxxxxxxx
<mailto:christopher.delahunt@xxxxxxxxxx>> wrote:

    I am not sure exactly what you mean, so I'll start by make a general
    warning;  Performing a refresh when there are changes can be risky,
    as it essentially resets the refreshed entity to what it is in the
    database.  Any changes you make that are not in the database might
    be lost.  And as cascade refresh/all seem to be overused, performing
    a refresh over an object tree can cause unintentionally wiping out
    changes to the tree.  Please note that refresh also resets lazy
    relationships, so that if you have A->B lazy relation marked cascade
    refresh and refresh A, then later on find and make changes to B in
    the same context, these changes might be wiped out when you access

    That said, what you are experience sounds like if you are updating
    you should flush the change before you issue a query that might
    cause a refresh.  Calling flush pushes the changes to the database
    so that they are picked up when the refresh occurs.

    Best Regards,
    Chris


    On 18/09/2012 3:32 PM, vaidya nathan wrote:

        Hi Eclipselink users,

        We are using eclipselink 2.4.0 and having a problem that is
        mystifying.
        We are using jboss as our container , and spring jta to write
        data and
        so far so good. While testing we found that whenever we make a
        change to
        the database directly the data is not getting refreshed
        automatically
        (The eclipselink cache is not getting refreshed automatically).
        So we
        introduced a hint something like

           Query jpaq = JpaHelper.createQuery(query, getEntityManager()) ;
           jpaq.setHint(QueryHints.__REFRESH, HintValues.TRUE) ;

        and with this it is refreshing . But the problem with this
        approach is
        that if we have an update and read within the same transaction ,
        it is
        not working. i think that the first update is just merging to
        the cache
        but when we do a find it is going and re reading it from the
        database
        and so am not getting the updates. How do i configure the hint
        to work
        in both the cases?

        Cheers
        Vaidya



        _________________________________________________
        eclipselink-users mailing list
        eclipselink-users@xxxxxxxxxxx <mailto:eclipselink-users@xxxxxxxxxxx>
        https://dev.eclipse.org/__mailman/listinfo/eclipselink-__users
        <https://dev.eclipse.org/mailman/listinfo/eclipselink-users>

    _________________________________________________
    eclipselink-users mailing list
    eclipselink-users@xxxxxxxxxxx <mailto:eclipselink-users@xxxxxxxxxxx>
    https://dev.eclipse.org/__mailman/listinfo/eclipselink-__users
    <https://dev.eclipse.org/mailman/listinfo/eclipselink-users>




_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top