I have several tables with basic lookup data in them (cd,description). I would like to be able to use the level 2 cache to cache the values as they are requested.
Basically I have several entity objects that hava a <many-to-one definition defined for the lookup value on that entity.
How do I get hibernate to use the cached values from the level 2 cache whenever a lookup value is referenced from a entity that has a reference to that lookup value?
I have EhCache implemented within my current app and I can get get the lookup values to be cached (I viewed the cache statistics) but the main entity (which is not cached) still issues a db select statement instead of pulling the lookup entity from the level 2 cache.
Here is a snippet of my hibernate mapping files:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<class name="com.foo.MainEntity" table="main_table" batch-size="30">
<id name="id" column="main_id" type="long">
<generator class="sequence">
<param name="sequence">main_id_seq</param>
</generator>
</id>
<many-to-one name="lookupType" class="com.foo.LookupEntity" column="le_id" not-null="true" lazy="proxy"/>
</class>
<class name="com.foo.LookupEntity" table="lookup_table" batch-size="30">
<cache usage="read-only"/>
<id name="id" column="le_id" type="long">
<generator class="sequence">
<param name="sequence">lookup_id_seq</param>
</generator>
</id>
<property name="name" column="name" not-null="true"/>
<property name="description" column="description" not-null="true"/>
</class>
</hibernate-mapping>