Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » second level cache without persistence.xml
second level cache without persistence.xml [message #1124572] Thu, 03 October 2013 13:25 Go to next message
Eclipse UserFriend
I'm using eclipse link and spring as follow

<bean id="emf"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
                <property name="generateDdl" value="false"/>
                <property name="showSql" value="true" />
                <property name="database" value="POSTGRESQL"/>
                <property name="databasePlatform" value="org.eclipse.persistence.platform.database.PostgreSQLPlatform"/>
            </bean>
        </property>
        <property name="jpaDialect">
            <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect"/>
        </property>
        <property name="loadTimeWeaver">
            <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
        </property>
        <property name="packagesToScan" value="org.omid.model"/>
        <property name="jpaProperties">
            <props>               
                <prop key="eclipselink.cache.shared.default">false</prop>
                <prop key="eclipselink.query-results-cache">true</prop>
                <prop key="eclipselink.logging.session">true</prop>
            </props>
        </property>
    </bean>


as you can see because of packagesToScan I don't have persistence.xml.
my first question is how I can enable selective cache ?

I've tried this

@Entity
@Cacheable(true)
@Cache(
  type=CacheType.SOFT, // Cache everything until the JVM decides memory is low.
  size=64000,  // Use 64,000 as the initial cache size.
  expiry=36000000
)
public class Employee {
  ...
}

but it doesn't working.
am I missing something ?
Re: second level cache without persistence.xml [message #1125551 is a reply to message #1124572] Fri, 04 October 2013 12:39 Go to previous messageGo to next message
Eclipse UserFriend
How are you testing that it isn't working? Each EntityManager has its own first level cache, could that be what you are seeing?

Best Regards,
Chris
Re: second level cache without persistence.xml [message #1126065 is a reply to message #1125551] Sat, 05 October 2013 01:32 Go to previous messageGo to next message
Eclipse UserFriend
when I enable shared
<prop key="eclipselink.cache.shared.default">true</prop>
only first time query is executed but in the above case every time I try to load data query will be executed.
Re: second level cache without persistence.xml [message #1129422 is a reply to message #1126065] Tue, 08 October 2013 12:07 Go to previous message
Eclipse UserFriend
Everything is then working as you have configured it. The <prop key="eclipselink.cache.shared.default">true</prop> is the default, and enables the shared cache. Each entity's cache can then be individually configured using the @Cacheable annotations. EclpseLink defaults the JPA shared-cache-mode tag to DISABLE_SELECTIVE as described in http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/cache_usaged#Section_3.7.1_-_The_shared-cache-mode_element , so all entities will default to @Cacheable(true) - so all entities will use the shared cache by default unless @Cacheable(false) is specified. You probably want to use <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode> in your persistence.xml so that only entities with @Cacheable(true) use the shared cache.

Best Regards,
Chris


Previous Topic:BUG : postgresql @NamedStoredProcedureQuery call
Next Topic:Problem with Transaction Management
Goto Forum:
  


Current Time: Mon Jul 07 16:21:44 EDT 2025

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

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

Back to the top