1.hibernate 3.1的lazy默認值是true,需要注意。
2.針對這幾天的代碼:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Session session = hibernate.HibernateSessionFactory.getSession();

Jishuchuangxinzhongxin jishuchuangxinzhongxin = (Jishuchuangxinzhongxin) session
.load(Jishuchuangxinzhongxin.class, new Integer(Integer
.valueOf((String) request.getParameter("id"))
.intValue()));
System.out.println(jishuchuangxinzhongxin.getBiaoti());
request.setAttribute("jishuchuangxinzhongxin", jishuchuangxinzhongxin);

session.close();

return mapping.findForward("show_jishuchuangxinzhongxin");
}
如果去掉 System.out.println(jishuchuangxinzhongxin.getBiaoti());這句后,則findforward到JSP時就會出現錯誤,終其原因就是3.1默認就是延遲加載,在內部NEW了一個代理對象的引用。當加上 System.out.println(jishuchuangxinzhongxin.getBiaoti());這句后,hibernate 3.1初始化代理對象中的各個屬性,下一步session.close,雖然session是close關的,但JSP也可以訪問游離對象,所以不出錯。
3.避免上2條的錯誤,解決辦法有二:(1)設置class標記為lazy=false,即非延遲檢索 (2)使用session.get方法來代替session.load方法。因為session.get方法是立即檢索策略。
2.針對這幾天的代碼:















3.避免上2條的錯誤,解決辦法有二:(1)設置class標記為lazy=false,即非延遲檢索 (2)使用session.get方法來代替session.load方法。因為session.get方法是立即檢索策略。