Exception: No CurrentSessionContext configured!
org.hibernate.HibernateException: No CurrentSessionContext configured!
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:540)
at managers.UserManagerImpl.addUser(UserManagerImpl.java:19)
at client.Client.main(Client.java:15)
Exception in thread "main" java.lang.NullPointerException
at managers.UserManagerImpl.addUser(UserManagerImpl.java:32)
at client.Client.main(Client.java:15)
解决方案:[color=blue][/color]
使用了sessionFactory.getCurrentSession()但在hibernate.cfg.xml中没有配置
如果是web应用增加配置
<property name="current_session_context_class">jta</property>
如果是Java应用,增加如下配置
<property name="current_session_context_class">thread</property>
引用
1、getCurrentSession()与openSession()的区别?
* 采用getCurrentSession()创建的session会绑定到当前线程中,而采用openSession()
创建的session则不会
* 采用getCurrentSession()创建的session在commit或rollback时会自动关闭,而采用openSession()
创建的session必须手动关闭
2、使用getCurrentSession()需要在hibernate.cfg.xml文件中加入如下配置:
* 如果使用的是本地事务(jdbc事务)
<property name="hibernate.current_session_context_class">thread</property>
* 如果使用的是全局事务(jta事务)
<property name="hibernate.current_session_context_class">jta</property>
分享到:
相关推荐
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. 网上的方法都是在CentOS下进行的,而我用的是Deepin系统,也就是基于Ubuntu/Debian的发行版...
问题:安装Pycharm了就可以直接运行程序了吗? 回答:不能!!! PyCharm是一种Python IDE,带有一整套可以帮助...如果没有配置解释器就直接运行,则会出现显示:“No python interpreter configured for the projec
*Mar 1 00:04:37.359: %SYS-5-CONFIG_I: Configured from console by console r1#ping 3.3.3.3 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds: !!!!! Success ...
主要给大家介绍了关于Spring Boot报错:No session repository could be auto-configured, check your configuration的解决方法,文中给出了详细的解决方法,对遇到这个问题的朋友们具有一定参考价值,需要的朋友...
Docker创建php开发环境遇到的权限问题解决方案.docx
SAM7A3 Flash - ULINK: configured for on-chip Flash ROM, using ULINK (used for production or target debugging) SAM7A3 RAM - ULINK: configured to run from on-chip RAM, using ULINK (may be used for ...
*Mar 1 00:07:27.839: %SYS-5-CONFIG_I: Configured from console by console r1#telnet 23.1.1.2 Trying 23.1.1.2 ... Open User Access Verification Username: xiaoan Password: r3>en % No password set r3>...
本文详细介绍了JLINK工具的用法,以及KEIL环境下配置配置J-Link在RAM中调试的方法
/bin/bashMavenSQL Workbench (or equivalent)IDEA configured with Springboot helpsJDK 1.8 (min)Your favorite internet browser正在安装 :hammer_and_wrench: #! /bin/bashcd ./yourWorkspace/git cone htt
rocketmq可视化控制台最新版
SQL Server not configured for data access问题处理 用于跨数据库连接
路由器4 用于API调用的axios 其他很棒的东西:poppers,styledComponents,sass-configured webpack捆绑了所有主要资产-css / scss jpg / gif / png svg 通过webpack-dev-server在本地服务webpack,eslint已完全...
Note: If you have previously configured a PXF JDBC server to access Kerberos-secured Hive, you must upgrade the server definition. See Upgrading PXF in Greenplum 6.x for more information. Changed ...
错误1: ./configure checking for getifaddrs... yes checking ifaddrs.h usability......checking ifaddrs.h presence......checking for ifaddrs.h......checking for socklen_t......checking for getaddrinfo......
*Mar 1 00:02:58.663: %SYS-5-CONFIG_I: Configured from console by console Current configuration : 1078 bytes ! version 12.4 service timestamps debug datetime msec service timestamps log datetime msec ...
本文主要对Struts的源代码进行分析,因为Struts2与WebWork的关系如此密不可分,因此,读者需要下载xwork的源代码,访问http://www.opensymphony.com/xwork/download.action即可自行下载。 下载的Struts2源代码文件...
eslint-config-u-sho-vue3-ts Vue 3 + TypeScript针对u-sho的ESLint规则。
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is
There is no in-place upgrade available. To install Oracle SQL Developer 2.1 download the file and unzip into an empty folder. Select the "Use folder names" checkbox when unzipping the file. You can ...
开始学习爬虫,但是在第一天就遇到了大问题,在命令行安装selenium一直提示下列SSL有问题:WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available...