Hibernate Books

All times are UTC - 5 hours [ DST ]

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Ehcache not working 2nd level and query cache in WAS.
PostPosted: Sun Jun 04, 2017 3:39 am 

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.

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

<!-- 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" />


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

<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" />
<property name="displayName" type="string" />
<property name="displayNameAr" type="string" />


<!-- parsed in 0ms -->

 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: 1228
As explained in this article, the Query Cache requires you to manually enable the cachability on a per query basis:

public List<Post> getLatestPosts(Session session) {
    return (List<Post>) session.createQuery(
        "select p " +
        "from Post p " +
        "order by p.createdOn desc")

However, as I explained in my book, High-Performance Java Persistence, the Query Cache is not as useful as you might think. In fact, DB caching and replication are much more suitable for reducing read-only query latency and to increase read-only query throughput.

If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.