`
smartan
  • 浏览: 183074 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Exception: No CurrentSessionContext configured!

    博客分类:
  • SSH
 
阅读更多
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>  
0
0
分享到:
评论

相关推荐

    Ubuntu/Deepin下Python3.8出现SSL错误的解决方案

    WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. 网上的方法都是在CentOS下进行的,而我用的是Deepin系统,也就是基于Ubuntu/Debian的发行版...

    Hibernate源代码分析

    throw new HibernateException("No CurrentSessionContext configured!"); } return currentSessionContext.currentSession(); } 在 getCurrentSession() 方法中,SessionFactoryImpl 将获取 Session 的工作委托...

    hibernate测试时遇到的几个异常及解决方法汇总

    3. org.hibernate.HibernateException: No CurrentSessionContext configured! 该异常的解决方法是添加 hibernate-jpa-2.0-api-1.0.0.Final.jar。这是因为 Hibernate 需要配置 CurrentSessionContext,以便正确地...

    Hibernate源代码分析(一)

    throw new HibernateException( "No CurrentSessionContext configured!" ); } return currentSessionContext.currentSession(); } 从上面的代码可以看到,getCurrentSession 方法将获得 Session 对象的工作委托...

    Spring Boot报错:No session repository could be auto-configured, check your configuration的解决方法

    在Spring Boot应用中,当你遇到“`No session repository could be auto-configured, check your configuration`”的错误时,这通常意味着Spring Boot无法自动配置用于管理会话(session)的存储库。Spring Boot提供...

    ccna实验之NAT,用的是繁荣模拟器

    *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 ...

    datax Jar.zip

    datax是很好的数据同步工具,但是网上大多数基于python指令来运行。本资源是基于ali的datax项目源码改编,直接打包成core和depend两个jar包。可以直接添加到java项目中,通过方法Engine.run("datax-plugin路径","....

    AT91SAM7A3-EK.rar_AT91SAM7A3_ATMEL flash_On The Run_ice FLASH_sa

    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 ...

    Docker创建php开发环境遇到的权限问题解决方案.docx

    #### 背景介绍 随着容器化技术的发展,越来越多的企业选择使用 Docker 来部署他们的开发、测试甚至是生产环境。通过 Docker,可以快速搭建出一个隔离的环境,使得开发、测试与生产环境尽可能保持一致,从而减少“在...

    ccna实验之acl,用的是繁荣的模拟器。

    *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&gt;en % No password set r3&gt;...

    SQL Server not configured for data access问题处理

    SQL Server not configured for data access问题处理 用于跨数据库连接

    eTin:偶尔转变那些讨厌的习惯,以帮助您关心自己的行为!

    /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可视化控制台最新版 rocketmq-console-ng-2.x

    RocketMQ是一款开源的消息中间件,由阿里巴巴开发并贡献给Apache软件基金会,被广泛应用于大数据、实时计算、微服务等场景。RocketMQ的核心功能包括消息发送与接收、消息队列、消息回溯、高可用保障、分布式事务等。...

    KEIL中配置J-Link在RAM中调试的方法

    本文详细介绍了JLINK工具的用法,以及KEIL环境下配置配置J-Link在RAM中调试的方法

    reactTemplate16dot8

    路由器4 用于API调用的axios 其他很棒的东西:poppers,styledComponents,sass-configured webpack捆绑了所有主要资产-css / scss jpg / gif / png svg 通过webpack-dev-server在本地服务webpack,eslint已完全...

    Ubuntu常见错误问题的解决方法小结

    错误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......

    ccna实验之ppp 用的是繁荣模拟器

    *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 ...

    struts2源码解析,个人感觉很不错

    ### Struts2源码解析及工作原理 #### Struts2简介 Struts2是一个流行的Java Web应用程序框架,它继承和发展了Struts1.x的一些特性,同时又采用了WebWork框架的核心技术,使得Struts2在设计理念和技术实现上都有了...

    eslint-config-u-sho-vue3-ts:适用于vue3 + ts的可共享eslint配置

    《Vue 3 + TypeScript的eslint配置实践:eslint-config-u-sho-vue3-ts》 在现代Web开发中,代码质量和一致性至关重要。为了实现这一目标,开发者通常会借助于静态代码分析工具,例如ESLint。`eslint-config-u-sho-...

    Oracle SQL Developer 2.1.0.63.73 for 32bit-windows-no-jre.part1

    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 ...

Global site tag (gtag.js) - Google Analytics