Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Web struts
Hi.
 
My project is a web project based on Struts2 + Spring + Hibernate.
And I'm using MySQL.
I'm defining beans and applying DI( Dependency Injection ).
All beans have 'request' scope, but only org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean instance is 'singleton'.
 
<bean id="sessionFactory" scope="singleton"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="configLocation" value="classpath:hibernate.cfg.xml" />
	</bean>
 

Problems are as following.
 
1. I run my project.
 
2. I connected to my project on the web browser.
 
http://localhost:8080/myproj
 
3. Here display the table rows in my database.
 
4. Then, I changed a row in the database on PHPMyAdmin.
 
5. I refresh my page, but the page is showing the unchanged data.
 
What's the problem?
Please help me.
Posted 12-Mar-13 23:15pm
Edited 12-Mar-13 23:18pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello,
 
Hibernate has two possible places where data can get cached, in the first level cache (the Session) or the second level cache (some third party cache implementation).
The first level cache is always used when you open a Session and load an object into it. You can update this object's properties all you like, its only when the session is flushed or closed (by calling those methods on the session) that the object's properties are persisted to the database.
 
The second level cache is only used if you explicitly add caching declarations to your mapping files. Otherwise it is not used.
 
Given this I suspect that you are not properly closing the session and that's why you are able to see the changes. If you have second level cache (EHCache) then use following xml to disable it. Disabling first level cache is not recommended and there is not suitable way to di this. You can use session.evict(YOUR OBJECT) to remove your object from this cache though.
<!-- 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.EhCacheRegionFactory
</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_structured_entries">true</property>     
<property name="hibernate.cache.generate_statistics">true</property>
Regards,
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 24 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100