page1.jsp list all information of a table
the scripts are as follow:
<%
Query paperQuery = hisession.createQuery("select paper from Paper paper");
Iterator iterator = paperQuery.iterate();
while(iterator.hasNext()) {
Paper tempPaper = (Paper)iterator.next();
//...
}
%>
page2.jsp,update a row of the table,as follows:
<%
net.sf.hibernate.Session hisession = HibernateUtil.currentSession();
java.util.List paperList = hisession.find("select paper from Paper paper where paper.id=" + Util.getRequestInt(request,"paperid"));
Paper thepaper = (Paper)paperList.get(0);
thepaper.setHitcounts(thepaper.getHitcounts() + 1);
hisession.save(thepaper);
hisession.flush();
%>
page2 and write database successfully,but when I return to page1 and flush,the infomation may keep the same! Keep flushing it is possible to see updated infomation and but not sure,it may even show the information before updated.
I observed if table paper has two columns:
id,hitcounts
and id is the primary key.
at first there is a row(1,10),pape1.jsp show the column correctly.
when pape2.jsp is executed the database has been updated to (1,11),
if pape2.jsp is executed one more time,the database has been updated to (1,12).
If now pape1.jsp is executed,the above three possible results may be shown,what is want is the last one!!
Notice I've called Session.flush() after update in page2.jsp.
What's the problem????
Can you help me,please!
|