2013年10月31日星期四

SSH in hibernate a cache problem ( help )

SSH in dao layer is mainly responsible for the database CRUD ; business layer component of the facade is dao , dao by combining multiple functions needed to achieve business ;
Hibernate uses spring template HibernateTemplate, session agent is spring , spring is responsible for the closing session , such as:
public void save (Student transientInstance) {
log.debug ("saving Student instance");
try {
getHibernateTemplate (). save (transientInstance);
log.debug ("save successful");
} catch (RuntimeException re) {
log.error ("save failed", re);
throw re;
}
}
operation will automatically turn off after spring session, so session life cycle is too short it, a cache is not gone yet ?

public Student findById (java.lang.String id) {
log.debug ("getting Student instance with id:" + id);
try {
Student instance = (Student) getHibernateTemplate (). get (
"com.student.javabean.Student", id);
return instance;
} catch (RuntimeException re) {
log.error ("get failed", re);
throw re;
}
}



If the business layer has the following operations:
Student s = sdao.findById (sid);
Set courses = s.getCourses ();

will complain no session or session was closed
because the use of lazy loading , all will report this error . Description session has indeed been in dao layer closed.

If opensessionviewfilter ( extended session of the life cycle, from dao -> service -> Acion -> jsp (view) then close the session) Even so , session of a cache role seemingly not much ?
solving ?
or to give an example of practical use cache
------ Solution ------------ --------------------------------
a cache is a Session -level cache, it belongs transaction scope cache.

When the application calls the Session save (), update (), saveOrUpdate (), get () or load (), and call the query interface list (), iterate () or filter () method If the cache does not exist in the Session corresponding object , Hibernate will put the object into the first level cache. When clearing cache , Hibernate object- based cache state changes to synchronize update the database.

Overall : a cache to play a role mainly for long transaction operation, to reduce the frequency of interaction with the database frequently , such as : Select then continuously Update, final submission .
------ For reference only -------------------------------------- -
how Meirenhuida Yeah
------ For reference only ----------------------------- ----------
same question SSH integration , hibernate in a cache is not nothing a role ?

没有评论:

发表评论