Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Can I hint Eclipselink to use the shared cache after a native query
icon3.gif  Can I hint Eclipselink to use the shared cache after a native query [message #1710387] Tue, 06 October 2015 11:29
Fritjof Flechsig is currently offline Fritjof FlechsigFriend
Messages: 1
Registered: October 2015
Junior Member
I recently opened a topic at stackoverflow:

In a JPA (eclipselink) application I have an ejb business action which must execute a native query (oracle) before going on with non-native jpa calls. That native call is some kind of reporting, it does not select or even change any of my entities in database.

However eclipseLink marks the transaction dirty, and the following non-native jpa calls do not use the shared cache any more. This behavior is documented in the eclipseLink userguide, see here, and thus its expected.

But is there a way of telling eclipseLink not to mark the transaction dirty, eg some hint in the native query? I need the following jpa-queries to use the shared cache.

The code where the native query is created is part of an interceptor like this:

public class MyInterceptor {
    @PersistenceContext( name="xxxx" )  
    private EntityManager em;  
    Object init( InvocationContext context ) throws Exception {  
      // the result of the native query is a plain date resulting
      // from a non-trivial query of course
      Date now = (Date)em.createNativeQuery( "select sysdate from dual" )
      return context.proceed();  

The rest of the business logic is encapsulated in a ejb eg
public class BusinessEJB {
    private EntityManager em;
    @Interceptors( { MyInterceptor.class } )    	
    public List<Result> find() {
        // Result is quite complex with lots of related detail objects
        // which I would like to fetch from the shared cache.
        // The entity Result is annotated @Cacheable( false ) and the 
        // detail entities are @Cacheable( true ). persistence.xml contains 
        // <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
        return em.createNamedQuery("Result.findAll",Result.class)

Whenever I remove the interceptor everything is fine. When we enable the query log in persistence.xml we see no queries on the detail objects. But adding the interceptor results in lots of database calls fetching the details.

I use jee6 on glassfish with eclipselink 2.3.2
Previous Topic:[moxy] Same domain classes, different mapping for XML and JSON (dash-case vs camelCase)
Next Topic:Validation Exception on compound key
Goto Forum:

Current Time: Tue Apr 16 02:23:10 GMT 2024

Powered by FUDForum. Page generated in 0.14083 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top