Question description:
first I get the Sysuser and display it in my jsp page, it was correct . then I modify it and submit , the data sava into database successfully. then I get the same Sysuse obj second time. but this time the Sysuser obj is the old data before update. Obviously it invoke the cache obj . Then I begin to clear the cache use the statement such as :session.flush();
session.clear(); but I was no use!
How can I get the right Sysuser obj. And I find this question here and there. whether there are som way to not use the cache?
I'm waiting for your help! thanks!
Hibernate version:
hibernate-3.1beta3
Mapping documents:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.cglib.use_reflection_optimizer">true</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sigma</property>
<property name="hibernate.connection.username">sigma</property>
<property name="hibernate.connection.password">sigma</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="com/sigma/portal/db/Child.hbm.xml" />
<mapping resource="com/sigma/portal/db/Document.hbm.xml" />
<mapping resource="com/sigma/portal/db/Company.hbm.xml" />
<mapping resource="com/sigma/portal/db/Sysuser.hbm.xml" />
<mapping resource="com/sigma/portal/db/Filetype.hbm.xml" />
<mapping resource="com/sigma/portal/db/Parent.hbm.xml" />
<mapping resource="com/sigma/portal/db/Userole.hbm.xml" />
<mapping resource="com/sigma/portal/db/Depart.hbm.xml" />
<mapping resource="com/sigma/portal/db/Event.hbm.xml" />
<mapping resource="com/sigma/portal/db/Role.hbm.xml" />
<mapping resource="com/sigma/portal/db/Authorization.hbm.xml" />
<mapping resource="com/sigma/portal/db/Sysfunc.hbm.xml" />
<mapping resource="com/sigma/portal/db/Project.hbm.xml" />
</session-factory>
</hibernate-configuration>
Code between sessionFactory.openSession() and session.close():
the metho get obj:
public Sysuser getSysuser(String userid)
{
Sysuser user = null;
try {
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
user = (Sysuser)session.get(Sysuser.class,userid);
session.flush();
session.clear();
tx.commit();
HibernateUtil.closeSession();
} catch (Exception e) {
e.printStackTrace();
}
return user;
}
The metho modi Sysuser:
public void modiSysuser(Sysuser user){
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
session.update(user);
session.flush();
session.clear();
tx.commit();
HibernateUtil.closeSession();
}
Full stack trace of any exception that occurs:
Name and version of the database you are using:
mysql-4.18
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
|