@RequestMapping("/testing")
@Transactional
public String testing(HttpServletRequest request, final ModelMap model)
{
Criteria criteria = session.getCurrentSession().createCriteria(Student.class);
criteria.setReadOnly(true);
criteria.add(Restrictions.eq("id", "ID12345"));
List<Student> result = criteria.list();
Student abc = result.get(0);
abc.setFirstname("AAA");
Criteria criteria2 = session.getCurrentSession().createCriteria(Student.class);
criteria2.setReadOnly(false);
criteria2.add(Restrictions.eq("id", "ID12345"));
result = criteria2.list();
Student abc2 = result.get(0);
abc2.setFirstname("BBB");
return "testing";
}
正如上面的代码,它必须setReadOnly
为 true criteria
,所以firstName
不会AAA
(在数据库中),但它已将 重置setReadOnly
为 false criteria2
,为什么firstname
没有变成BBB
(在数据库中)?