• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using ehcache with hibernate please answer this

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
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">
<list>
<value>com/hyderabad/model/hibernate/User.hbm.xml</value> <value>com/hyderabad/model/hibernate/Category.hbm.xml</value>
</list>
</property>

<property name="hibernateProperties">
<props>
<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>
</props>
</property>
</bean>
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"/>
</id>
<property name="categoryName">
<column name="category_name" />
</property>
<property name="parentCategoryId">
<column name="parent_category_id" />
</property>
</class>
And in my ehcache.xml file i have this
<ehcache>
<diskStore path="java.io.tmpdir"/>

<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>

<cache name="com.hyderabad.model.Category"
maxElementsInMemory="3"
eternal="true"
overflowToDisk="false"
/>
</ehcache>

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.

Thanks
Rashid
 
Darvesh Niz
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any advice or opinion please

Thanks
reply
    Bookmark Topic Watch Topic
  • New Topic