在Web应用程序项目中使用Hibernate和MySQL数据库,主要使用JSF ,在我手动更改数据库并提交后,Hibernate没有检测到这些更改,而hibernate查询返回相同的内容旧的结果,直到我重新启动应用程序,变化变得可检测。我禁用了二级缓存,但仍然。
public List<Property> findAll() {
try {
session = DBUtils.openSession();
List<Property> resultList = (List<Property>) session.createCriteria(Property.class).add(Restrictions.eq("active", new Integer(1))).list();
DBUtils.closeSession(session);
return resultList;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public class DBUtils {
public static Configuration config;
public static SessionFactory factory;
static {
try {
config = new Configuration();
config.configure();
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(config.getProperties());
factory = config.buildSessionFactory(ssrb.build());
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static SessionFactory getSessionFactory() {
return factory;
}
public static Session openSession() {
try {
return getSessionFactory().openSession();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static boolean closeSession(Session session) {
try {
if (session != null && session.isOpen()) {
session.close();
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
答案 0 :(得分:0)
在阅读http://www.ovaistariq.net/597/understanding-innodb-transaction-isolation-levels/之后,它似乎被称为隔离级别 并在hibernate cfg.xml中设置,我的问题解决了
<property name="hibernate.connection.isolation">1</property>