第一个bug:The requested resource is not available
我改了包名,对应的application.xml文件的ref路径得修改,对应的对象对应的Bean.hbm.xml文件里的<hibernate-mapping package="com.abtc.bean">也得修改
第二个bug: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
找了个中文翻译:
通过定义好的sessionFactory的getCurrentSession()方法获取当前线程中绑定的session,而当前线程绑定的session是通过当前的事务产生的,产生如上的错误是因为没有配置事务。当前线程中没创建session,则出现以上信息。
有可能是没弄注解:
找了哈对应的注解,都是弄好咯哩。
dao @Repository
service @Service @Transactional
controller @Controller @RequestMapping(value="/")
显然我不是这种,继续百度解决
1 getCurrentSession创建的session会和绑定到当前线程,而openSession不会。
2 getCurrentSession创建的线程会在事务回滚或事物提交后自动关闭,而openSession必须手动关闭
这里getCurrentSession本地事务(本地事务:jdbc)时 要在配置文件里进行如下设置
* 如果使用的是本地事务(jdbc事务)
<property name="hibernate.current_session_context_class">thread</property>
* 如果使用的是全局事务(jta事务)
<property name="hibernate.current_session_context_class">jta</property>
getCurrentSession () 使用当前的session
openSession() 重新建立一个新的session
在一个应用程序中,如果DAO 层使用spring 的hibernate 模板,通过Spring 来控制session 的生命周期,则首选getCurrentSession ()。
未完待续……