Even the JPA spec does not have the concept of 2nd level cache I can use it with Hibernate as JPA vendor.
I just have to pass the specific properties for cache at persistence.xml and it works.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="SpringJpaPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<!-- A list of vendor-specific properties -->
<properties>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_minimal_puts" value="true"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
<property name="hibernate.cache.provider_configuration_file_resource_path" value="META-INF/ehcache.xml"/>
</properties>
</persistence-unit>
</persistence>
I just want to know how to evict the objects cached... Should I do that directly using the Cache API (in my case EhCache API)? I guess this is an ugly solution...