-->
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.  [ 2 posts ] 
Author Message
 Post subject: Ehcache not working 2nd level and query cache in WAS.
PostPosted: Sun Jun 04, 2017 3:39 am 
Newbie

Joined: Sun Jun 04, 2017 3:22 am
Posts: 1
Below is the configuration for the hibernate.cfg.xml and Title.hbm.xml, for ehcache. But still even after repeated attempts unable to cache query. and each time it access the DB object its query generates the sql query in logs for fetching the data from table. NO cache hit is there We have deployed the application in IBM Websphere applcation server 8.5.5.

hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>

<!-- Database connection settings -->
<property name="hibernate.connection.datasource">jdbc/eservicedb</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<!-- delegates to database (JDBC) transactions (default) -->
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>

<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">jta</property>
<!-- Enable the second-level cache -->
<property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</property>
<property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory</property>
<!-- enable second level cache and query cache -->
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="net.sf.ehcache.configurationResourceName">/UMCache.xml</property>
<property name="jta.UserTransaction">java:comp/websphere/UOWManager</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<property name="net.sf.ehcache.configurationResourceName">UMCache.xml</property>
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.cache.use_structured_entries">true</property>


<!-- Common package mapping files -->
<mapping resource="ae/rta/pta/security/dao/hibernate/Security.hbm.xml"/>
<mapping resource="ae/rta/pta/common/dao/hibernate/SystemProperty.hbm.xml"/>
<mapping resource="ae/rta/pta/common/dao/hibernate/User.hbm.xml"/>
<mapping resource="ae/rta/pta/common/dao/hibernate/TrafficFile.hbm.xml"/>
<mapping resource="ae/rta/pta/common/dao/hibernate/WSOperationLog.hbm.xml"/>
<mapping resource="ae/rta/pta/common/dao/hibernate/ErrorLog.hbm.xml"/>
<mapping resource="ae/rta/pta/sso/dao/hibernate/Token.hbm.xml"/>
<mapping resource="ae/rta/pta/um/dao/hibernate/Function.hbm.xml"/>
<mapping resource="ae/rta/pta/common/dao/hibernate/DraftCompany.hbm.xml"/>
<mapping resource="ae/rta/pta/crm/dao/hibernate/CRMCompany.hbm.xml"/>
<mapping resource="com/ibm/tdc/services/um/orm/DraftUser.hbm.xml" />
<!-- Ehcache enabled on Title object -->
<mapping resource="com/ibm/tdc/services/um/orm/Title.hbm.xml" />

</session-factory>
</hibernate-configuration>

Title.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.ibm.tdc.services.um.bo.Title" table="UM.TITLE">
<cache usage="read-only"></cache>
<id name="id" column= "TITLEID" >
<generator class="assigned" />
</id>
<property name="displayName" type="string" />
<property name="displayNameAr" type="string" />

</class>

</hibernate-mapping>
<!-- parsed in 0ms -->


Top
 Profile  
 
 Post subject: Re: Ehcache not working 2nd level and query cache in WAS.
PostPosted: Sun Jun 04, 2017 4:33 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
As explained in this article, the Query Cache requires you to manually enable the cachability on a per query basis:


Code:
public List<Post> getLatestPosts(Session session) {
    return (List<Post>) session.createQuery(
        "select p " +
        "from Post p " +
        "order by p.createdOn desc")
    .setMaxResults(10)
    .setCacheable(true)
    .list();
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.