| Author |
using ehcache with hibernate please answer this
|
Darvesh Niz
Ranch Hand
Joined: May 12, 2008
Posts: 99
|
|
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
Joined: May 12, 2008
Posts: 99
|
|
any advice or opinion please Thanks
|
 |
 |
|
|
subject: using ehcache with hibernate please answer this
|
|
|