在Hibernate.cfg.xml中设置 current_session_context_class属性值为thread,hibernate会自动使用线程局部变量保存当前进程的Session和食物对象