I don't know why I am not able to cache anything across two sessions using ehcache.
Hibernate version:
2.1.6
Mapping documents:
Code:
<class name="com.waypoint.rs.incident.Incident" table="RS_INCIDENT">
<meta attribute="class-description">
Represents an incident in the database
@author Sameet Nasnodkar
</meta>
<cache usage="read-write" />
<id name="incidentId" type="int" column="INCIDENT_ID">
<generator class="native"/>
</id>
<property name="name" type="string">
<meta attribute="use-in-tostring">true</meta>
<column name="NAME" not-null="true"/>
</property>
<property name="incidentDate" type="timestamp">
<column name="TIMESTAMP" not-null="true"/>
</property>
<property name="incidentModDate" type="timestamp">
<column name="MOD_TIMESTAMP"/>
</property>
<property name="status" type="com.waypoint.rs.incident.IncidentStatusType">
<meta attribute="use-in-tostring">true</meta>
<column name="STATUS" not-null="true"/>
</property>
<many-to-one name="host" class="com.waypoint.rs.incident.IncidentHost"
column="HOST_ID" cascade="none" />
<!-- Subclasses defined below here -->
<!-- Tripwire Incident Subclass -->
<joined-subclass name="com.waypoint.rs.incident.tripwire.TripwireIncident" table="RS_TW_INCDT">
<meta attribute="class-description">
Represents a tripwire incident in the database
@author Sameet Nasnodkar
</meta>
<key column="INCIDENT_ID"/>
<property name="startPoint" type="string">
<column name="STARTPOINT" not-null="true"/>
</property>
<property name="ticketNo" type="string" column="TICKET_NO" />
<property name="comments" type="string" column="COMMENTS" />
<property name="contact" type="string" column="CONTACT" />
<!-- Define the tripwire incident header -->
<component name="TripwireIncidentHeader"
class="com.waypoint.rs.incident.tripwire.TripwireIncidentHeader">
<meta attribute="class-description">
Represents a tripwire incident header
@author Sameet Nasnodkar
</meta>
<property name="severity" type="int" column="SEVERITY"/>
<property name="onViolation" type="string" column="ON_VIOLATION"/>
<property name="match" type="string" column="MATCH"/>
<set name="emailAddresses" table="RS_TW_INCDT_EMAIL">
<key column="INCIDENT_ID"/>
<element column="email" type="string"/>
</set>
</component>
<!-- Define the tripwire incident summary -->
<component name="TripwireIncidentSummary"
class="com.waypoint.rs.incident.tripwire.TripwireIncidentSummary">
<meta attribute="class-description">
Represents a tripwire incident header
@author Sameet Nasnodkar
</meta>
<property name="violationCount" type="int" column="VIOLATIONCOUNT"/>
<property name="addedCount" type="int" column="ADDEDCOUNT"/>
<property name="changedCount" type="int" column="CHANGEDCOUNT"/>
<property name="removedCount" type="int" column="REMOVEDCOUNT"/>
</component>
<set name="errors" table="RS_TW_INCDT_ERRORS">
<key column="INCIDENT_ID"/>
<element column="error" type="string"/>
</set>
<set name="added" cascade="all-delete-orphan" where="OBJECT_TYPE='ADDED'">
<key column="INCIDENT_ID"/>
<one-to-many class="com.waypoint.rs.incident.tripwire.AddedTripwireIncidentObject"/>
</set>
<set name="changed" cascade="all-delete-orphan" where="OBJECT_TYPE='CHANGED'">
<key column="INCIDENT_ID"/>
<one-to-many class="com.waypoint.rs.incident.tripwire.ChangedTripwireIncidentObject"/>
</set>
<set name="removed" cascade="all-delete-orphan" where="OBJECT_TYPE='REMOVED'">
<key column="INCIDENT_ID"/>
<one-to-many class="com.waypoint.rs.incident.tripwire.RemovedTripwireIncidentObject"/>
</set>
<!--set name="added" cascade="all-delete-orphan" inverse="true">
<key column="INCIDENT_ID"/>
<one-to-many class="com.waypoint.rs.incident.tripwire.TripwireIncidentObject"/>
</set>
<set name="changed" cascade="all-delete-orphan" inverse="true">
<key column="INCIDENT_ID"/>
<one-to-many class="com.waypoint.rs.incident.tripwire.TripwireIncidentObject"/>
</set>
<set name="removed" cascade="all-delete-orphan" inverse="true">
<key column="INCIDENT_ID"/>
<one-to-many class="com.waypoint.rs.incident.tripwire.TripwireIncidentObject"/>
</set-->
</joined-subclass>
</class>
<query name="incidents.all">
<![CDATA[
from com.waypoint.rs.incident.Incident as i
where i.status like :iStatus
]]>
</query>
<query name="incidents.date.range">
<![CDATA[
from com.waypoint.rs.incident.Incident as i
where i.incidentDate > :startDate and i.incidentDate < :endDate
and i.status like :iStatus
]]>
</query>
<query name="incident.id">
<![CDATA[
from com.waypoint.rs.incident.Incident as incident
where incident.incidentId = :id
]]>
</query>
<query name="incidents.lastposting.date">
<![CDATA[
select distinct max(i.incidentDate) from com.waypoint.rs.incident.Incident as i
]]>
</query>
<query name="incidents.count.date.range">
<![CDATA[
select count(*) from com.waypoint.rs.incident.Incident as i
where (i.incidentDate > :startDate and i.incidentDate < :endDate)
and i.status like :iStatus
]]>
</query>
<query name="incidents.count.mod_date.range">
<![CDATA[
select count(*) from com.waypoint.rs.incident.Incident as i
where (i.incidentModDate > :startDate and i.incidentModDate < :endDate)
and i.status like :iStatus
]]>
</query>
<query name="incidents.count.all">
<![CDATA[
select count(*) from com.waypoint.rs.incident.Incident as i
where i.status like :iStatus
]]>
</query>
Code between sessionFactory.openSession() and session.close():Code:
Query query = session.getNamedQuery("incidents.all");
String statusName = (status == null) ? "%" : status.getName();
query.setString("iStatus", statusName);
query.setCacheable(true);
query.setCacheRegion("com.waypoint.rs.incident.Incident");
Iterator qIter = query.iterate();
logger.debug("Iterator class is " + qIter.getClass().getName());
// Add all the elements from the iterator to the list
for(; qIter.hasNext(); incidents.add(qIter.next()));
//incidents.addAll(query.list());
Full stack trace of any exception that occurs:None
Name and version of the database you are using:Postgresql 7.4.1
The generated SQL (show_sql=true):Debug level Hibernate log excerpt:Code:
2004-10-14 14:24:15,781 [net.sf.ehcache.hibernate.Plugin.get] DEBUG - key: 33621
2004-10-14 14:24:15,781 [net.sf.ehcache.store.MemoryStore.get] DEBUG - com.waypoint.rs.incident.IncidentCache: MemoryStore miss for 33621
2004-10-14 14:24:15,781 [net.sf.ehcache.Cache.get] DEBUG - com.waypoint.rs.incident.Incident cache - Miss
2004-10-14 14:24:15,781 [net.sf.ehcache.hibernate.Plugin.get] DEBUG - Element for 33621 is null
2004-10-14 14:24:15,781 [net.sf.hibernate.impl.BatcherImpl.getPreparedStatement] DEBUG - select incident0_.INCIDENT_ID as INCIDENT1_1_, case when incident0__1_.INCIDENT_ID is not null then 1 when incident0_.INCIDENT_ID is not null then 0 end as clazz_1_, incident0_.NAME as NAME22_1_, incident0_.TIMESTAMP as TIMESTAMP22_1_, incident0_.MOD_TIMESTAMP as MOD_TIME4_22_1_, incident0_.STATUS as STATUS22_1_, incident0_.HOST_ID as HOST_ID22_1_, incident0__1_.STARTPOINT as STARTPOINT23_1_, incident0__1_.TICKET_NO as TICKET_NO23_1_, incident0__1_.COMMENTS as COMMENTS23_1_, incident0__1_.CONTACT as CONTACT23_1_, incident0__1_.SEVERITY as SEVERITY23_1_, incident0__1_.ON_VIOLATION as ON_VIOLA7_23_1_, incident0__1_.MATCH as MATCH23_1_, incident0__1_.VIOLATIONCOUNT as VIOLATIO9_23_1_, incident0__1_.ADDEDCOUNT as ADDEDCOUNT23_1_, incident0__1_.CHANGEDCOUNT as CHANGED11_23_1_, incident0__1_.REMOVEDCOUNT as REMOVED12_23_1_, incidentho1_.HOST_ID as HOST_ID0_, incidentho1_.HOSTNAME as HOSTNAME0_, incidentho1_.IPADDRESS as IPADDRESS0_ from RS_INCIDENT incident0_ left outer join RS_TW_INCDT incident0__1_ on incident0_.INCIDENT_ID=incident0__1_.INCIDENT_ID left outer join RS_INCDT_HOST incidentho1_ on incident0_.HOST_ID=incidentho1_.HOST_ID where incident0_.INCIDENT_ID=?
2004-10-14 14:24:15,781 [net.sf.ehcache.hibernate.Plugin.get] DEBUG - key: 33621
2004-10-14 14:24:15,781 [net.sf.ehcache.store.MemoryStore.get] DEBUG - com.waypoint.rs.incident.IncidentCache: MemoryStore miss for 33621
2004-10-14 14:24:15,781 [net.sf.ehcache.Cache.get] DEBUG - com.waypoint.rs.incident.Incident cache - Miss
2004-10-14 14:24:15,781 [net.sf.ehcache.hibernate.Plugin.get] DEBUG - Element for 33621 is null
My hibernate.cfg.xml is as follows :
Code:
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.Provider</property>
My ehcache.xml contains the following :
Code:
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
/>
<cache name="com.waypoint.rs.incident.Incident"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="true"
/>
<cache name="com.waypoint.rs.incident.TripwireIncident.added"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="true"
/>
<cache name="com.waypoint.rs.incident.TripwireIncident.removed"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="true"
/>
<cache name="com.waypoint.rs.incident.TripwireIncident.changed"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="true"
/>