亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Sping管理hibernate時的事務問題(No Hibernate Session bound to thread)

Sping管理hibernate時的事務問題(No Hibernate Session bound to thread)

手掌心 2019-04-19 16:11:45
報錯:Exceptioninthread"main"org.hibernate.HibernateException:NoHibernateSessionboundtothread,andconfigurationdoesnotallowcreationofnon-transactionalonehereatorg.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)atorg.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:685)atcn.itcast.oa.util.Installer.install(Installer.java:24)atcn.itcast.oa.util.Installer.main(Installer.java:88)報錯代碼片段:Java代碼:@ComponentpublicclassInstaller{@ResourceprivateSessionFactorysessionFactory;@Transactionalprivatevoidinstall(){Sessionsession=sessionFactory.getCurrentSession();//保存超級管理員賬戶Useruser=newUser();user.setLoginName("admin");user.setName("超級管理員");user.setPassword(DigestUtils.md5Hex("admin"));session.save(user);//保存權限數據Privilegemenu,menu1,menu2,menu3,menu4,menu5;//=====menu=newPrivilege("系統管理",null,null);menu1=newPrivilege("崗位管理","/role_list",menu);menu2=newPrivilege("部門管理","/department_list",menu);menu3=newPrivilege("用戶管理","/user_list",menu);session.save(menu);session.save(menu1);session.save(menu2);session.save(menu3);}publicstaticvoidmain(String[]args){ApplicationContextac=newClassPathXmlApplicationContext("applicationContext.xml");Installerinstaller=(Installer)ac.getBean("installer");installer.install();}}Spring配置文件:
查看完整描述

2 回答

?
躍然一笑

TA貢獻1826條經驗 獲得超6個贊

報錯:Exceptioninthread"main"org.hibernate.HibernateException:NoHibernateSessionboundtothread,andconfigurationdoesnotallowcreationofnon-transactionalonehere
報錯很明顯了,然后你的評論問題為什么opensession可以?
推薦你2個帖子看一下SSH中使用getCurrentSession()獲得session
getCurrentSession與openSession()的區別,雖然寫的早了點和你用的配置不太相同,但hibernate的實現是一樣的。當然如果還是不太明白的話,那就問問給你教材的人吧。。
                            
查看完整回答
反對 回復 2019-04-19
  • 2 回答
  • 0 關注
  • 322 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號