-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: EHcache not caching anything ....
PostPosted: Thu Oct 14, 2004 3:32 pm 
Beginner
Beginner

Joined: Fri Aug 13, 2004 3:07 pm
Posts: 44
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"
        />

_________________
Thanks
Sameet


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 15, 2004 10:08 am 
Beginner
Beginner

Joined: Fri Aug 13, 2004 3:07 pm
Posts: 44
I got the answer. I was recreating the configuration object and session factory everytime, hence I was ending up with a new cache everytime. Thanks to Christian's book I finally understood that the secondlevel cache is at the SessionFactory level. Now I need to figure out how to make it work across different web users. Hibernate is killing the cache everytime I logout. So when I log back in, I get the following exception

Code:
java.lang.IllegalStateException: The com.waypoint.rs.incident.Incident Cache is not alive.
   at net.sf.ehcache.Cache.checkStatus(Cache.java:437)
   at net.sf.ehcache.Cache.get(Cache.java:217)
   at net.sf.ehcache.hibernate.Plugin.get(Plugin.java:119)
   at net.sf.hibernate.cache.ReadWriteCache.get(ReadWriteCache.java:73)
   at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2104)
   at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1987)
   at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1949)
   at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:69)
   at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:204)
   at net.sf.hibernate.type.EntityType.nullSafeGet(EntityType.java:126)
   at net.sf.hibernate.impl.IteratorImpl.postNext(IteratorImpl.java:85)
   at net.sf.hibernate.impl.IteratorImpl.<init>(IteratorImpl.java:62)
   at net.sf.hibernate.hql.QueryTranslator.iterate(QueryTranslator.java:861)
   at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1608)
   at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:27)
   at com.waypoint.rs.incident.IncidentManager.getIncidents(IncidentManager.java:95)
   at com.waypoint.tripwire.rs.servlet.IncidentServlet.processHome(IncidentServlet.java:125)
   at com.waypoint.tripwire.rs.servlet.IncidentServlet.doGet(IncidentServlet.java:48)
   at com.waypoint.tripwire.rs.servlet.IncidentServlet.doPost(IncidentServlet.java:69)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:703)
   at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
   at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
   at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
   at com.waypoint.tripwire.rs.servlet.BaseServlet.forwardToPage(BaseServlet.java:55)
   at com.waypoint.tripwire.rs.servlet.LoginServlet.doGet(LoginServlet.java:57)
   at com.waypoint.tripwire.rs.servlet.LoginServlet.doPost(LoginServlet.java:70)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
   at java.lang.Thread.run(Thread.java:534)

_________________
Thanks
Sameet


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 15, 2004 10:37 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
Hibernate is killing the cache everytime I logout.


hi sameet,
what do you mean by "log out" what are you doing there? can you show us the code?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 17, 2004 9:58 pm 
Beginner
Beginner

Joined: Fri Aug 13, 2004 3:07 pm
Posts: 44
Anthony,

I figured out the problem. It was the same issue, I had not changed all my code to use the common sessionfactory object. Anyways, thanks for the input. [/quote]

_________________
Thanks
Sameet


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.