It's not a secret anymore!
The moose likes EhCache and the fly likes using ehcache with hibernate please answer this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Caching » EhCache
Bookmark "using ehcache with hibernate please answer this" Watch "using ehcache with hibernate please answer this" New topic

using ehcache with hibernate please answer this

Darvesh Niz
Ranch Hand

Joined: May 12, 2008
Posts: 121
i have a very few basic but important question about hibernate.
i have a POJO defined as category and i have set the cache as read-only and i integrated Ehcache with my project on second level.
Here is a snippet from my application-context file, i have sepcified the ehcahce provider
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
<value>com/hyderabad/model/hibernate/User.hbm.xml</value> <value>com/hyderabad/model/hibernate/Category.hbm.xml</value>

<property name="hibernateProperties">
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
The next thing i did was in my Category.hbm.xml file i gave the cache usage something like this
<class name="com.hyderabad.model.Category" table="category">
<cache usage="read-only" />
<id name="categoryId" column="category_id">
<generator class="increment"/>
<property name="categoryName">
<column name="category_name" />
<property name="parentCategoryId">
<column name="parent_category_id" />
And in my ehcache.xml file i have this
<diskStore path=""/>


<cache name="com.hyderabad.model.Category"

I have the following questions...
1) i gave the maximum elements for category to be 3 but when i run my project i get all the 20 categories. Why? My wild guess i read in some forums i have to enable second level categories by using some property element.

2)When i start my container i get 20 categories. Ok fine, but when i add manually some more categories in my database table and refresh the page those new entries are showing up, i thought if you implement the cache usage as read only and at the second level (at session factory level) then the server should be bounced to read the newly added categories. i am having a wrong about it.

Any advice.

Darvesh Niz
Ranch Hand

Joined: May 12, 2008
Posts: 121
any advice or opinion please

I agree. Here's the link:
subject: using ehcache with hibernate please answer this
It's not a secret anymore!