Hi,
I have a spring JPA hibernate app and I am trying to switch on second level caching but I am unsure if it is actually working as I can still see the SQL on the console (I am pretty sure that means it is not working). ANy help would be greatly appreciated. Thanks.
Here is my config & code...
Object...
Code:
@Entity()
@Table(name = "wiki_file")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class WikiFile {
...
persistance.xml
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" version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="medical">
<properties>
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
</properties>
</persistence-unit>
</persistence>
application context...
Code:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="MYSQL" />
<property name="showSql" value="true" />
<property name="generateDdl" value="true"></property>
</bean>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/medical" />
<property name="username" value="yee" />
<property name="password" value="haa" />
</bean>
When I ask for the object repeatedly it shows the select being run again
Code:
Hibernate: select wikifile0_.wiki_file_id as wiki1_3_, wikifile0_.ADMIN_only as ADMIN2_3_, wikifile0_.content as content3_, wikifile0_.delete_date as delete4_3_, wikifile0_.file_name as file5_3_, wikifile0_.file_size as file6_3_, wikifile0_.mime_type as mime7_3_, wikifile0_.read_only as read8_3_, wikifile0_.virtual_wiki as virtual9_3_ from wiki_file wikifile0_ where wikifile0_.wiki_file_id=2 limit ?
Hibernate: select wikifile0_.wiki_file_id as wiki1_3_, wikifile0_.ADMIN_only as ADMIN2_3_, wikifile0_.content as content3_, wikifile0_.delete_date as delete4_3_, wikifile0_.file_name as file5_3_, wikifile0_.file_size as file6_3_, wikifile0_.mime_type as mime7_3_, wikifile0_.read_only as read8_3_, wikifile0_.virtual_wiki as virtual9_3_ from wiki_file wikifile0_ where wikifile0_.wiki_file_id=2 limit ?
Hibernate: select wikifile0_.wiki_file_id as wiki1_3_, wikifile0_.ADMIN_only as ADMIN2_3_, wikifile0_.content as content3_, wikifile0_.delete_date as delete4_3_, wikifile0_.file_name as file5_3_, wikifile0_.file_size as file6_3_, wikifile0_.mime_type as mime7_3_, wikifile0_.read_only as read8_3_, wikifile0_.virtual_wiki as virtual9_3_ from wiki_file wikifile0_ where wikifile0_.wiki_file_id=2 limit ?
If I leave out the hibernate.cache.use_second_level_cache in the persitance.xml file hibernate complains about the object so I know that hibernate knows the object is to be cached I just cannot see any evidence that it is (or not).
Thanks.
hibernate 3.2 spring 3.0.5