Reputation: 65
I have an entity with named query.
@Entity(name = "MyEntity")
@Table(name = "mytable")
//@ReadOnly
@NamedQueries({
@NamedQuery(
name = "exampleFind",
query = "[..]",
hints = {@QueryHint(name= QueryHints.QUERY_RESULTS_CACHE, value= "TRUE")})
})
@Cacheable
@Cache(type = CacheType.FULL)
public class MyEntity {
When I annotate this class with @ReadOnly then this query does not hit the database (uses results cache only) but when I remove @ReadOnly annotation it always performs SQL on database.
How to enable this cache without @ReadOnly? Are there any limitations on results cache?
I use EclipseLink 2.4.1
Upvotes: 2
Views: 1577
Reputation: 20760
In our application we had some trouble getting the query cache to work as well. You need to make sure that your entities and your query results are cached.
For us it works when we set the shared-cache-mode in the persistence.xml
to DISABLE_SELECTIVE
:
<shared-cache-mode>DISABLE_SELECTIVE</shared-cache-mode>
Together with this we use @Cache
to configure the type of caching we want for our entities. And @Cacheable(false)
to disable it for some.
According the developers manual this setting actually is the default, so removing your current setting should also work.
Upvotes: 2