Because I am not familiar with springside3, I haven't found the XML file for configuring hiberante for a long time. I finally searched for it and came out:
There is a section in E: \ myeclipseworkplace \ lforum \ webapp \ WEB-INF \ config \ applicationcontext. xml:
<! -- Hibernate configuration --> < Bean ID = "Sessionfactory" Class = "Org. springframework. Orm. hibernate3.annotation. annotationsessionfactorybean" > < Property Name = "Datasource" Ref = "Datasource" /> < Property Name = "Namingstrategy" > < Bean Class = "Org. hibernate. cfg. improvednamingstrategy" /> </ Property > < Property Name = "Hibernateproperties" > < Props > < Prop Key = "Hibernate. dialect" > Db_dialect </ Prop > < Prop Key = "Hibernate. show_ SQL" > $ {Hibernate. show_ SQL} </ Prop > < Prop Key = "Hibernate. cache. provider_class" > Org. hibernate. cache. ehcacheprovider </ Prop > < Prop Key = "Hibernate. cache. provider_configuration_file_resource_path" > Ehcache-hibernate.xml </ Prop > </ Props > </ Property > < Property Name = "Packagestoscan" Value = "Com. javaeye. lonlysky. lforum. entity *, Com. javaeye. lonlysky. lforum. entity .*" /> </ Bean >
So how to update the cache?
Cache has three main aspects in hibernate: level-1 cache, level-2 cache, and query cache; level-1 cache corresponds to session-range cache in hibernate,
That is, when the session is closed, the cache is cleared, and the first-level cache is not configurable in hibernate. The second-level cache corresponds to the sessionfactory cache in hibernate,
Generally, the life cycle of sessionfactory is the same as that of the application, so it can be regarded as process cache or cluster cache,
The second-level cache can be configured in hibernate:
You can use Class-cache to configureClass-level cache(Class-cache is automatically updated when the data in the class changes ),
You can also use collection-cache to configureCache at collection granularity level(Collection-cache is automatically updated only when an element is added to or deleted from the collection,
That is, when the value of an element in the collection changes, it will not be automatically updated.) cache will naturally cause concurrent access problems, at this time, the transaction isolation level adopted by the cache should be set based on the application,
The concept of transaction isolation level is basically the same as that of the database. There is nothing to mention, ^ _ ^; query cache is also configurable in hibernate, and is disabled by default,
You can enable the query cache by setting cache. Use _ query_cache to true.
So in the object:
@ Entity @ table (name ="Forums") @ Cache (Usage = cacheconcurrencystrategy. read_write)Public ClassForumsImplementsJava. Io. serializable {.......}
Cacheconcurrencystrategy. read_write: When the read/write mode updates the cache, it will replace the data in the cache with a lock,
If other transactions fetch the corresponding cached data and find the data is locked, they can directly query the data in the database;
Cache at the class granularity level is enabled here.
Why is there a manual removecache operation in it:
The main reason is that the cache is not an entity, but a list of other things or entities, such as forumlistboxoptions,
Forumlist.