zoukankan      html  css  js  c++  java
  • sessionFactory中的openSession和getCurrentSession的一些注意事项

    今天进行Hibernate测试时遇到了一个问题

    我在用sessionFactory生产seesion时出现了故障,使用getCurrentsesstion时产生异常:

    Exception in thread "main" org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread

    应该是说在主线程中不能包含事务同步会话

    参考链接:

    https://blog.csdn.net/wang1472jian1110/article/details/42679217

    http://www.360doc.com/content/11/0502/19/987036_113784420.shtml

    优先推荐:https://blog.csdn.net/lmdcszh/article/details/13775933

    相同点

        openSession与getCurrentSession都可以创建session

    不同点

        * openSession没有绑定当前线程,所以,使用完后必须关闭,

        * currentSession和当前线程绑定,在事务结束后会自动关闭。

  • 相关阅读:
    redis 学习(17) -- RDB
    51单片机程序技巧
    无效设备解决办法
    210板子启动笔记
    RFID读卡器设置卡
    Socket简介
    /etc/hosts.conf
    TVP5150摄像头
    maven小试牛刀
    2014图灵技术图书最受欢迎TOP15
  • 原文地址:https://www.cnblogs.com/Sword007/p/10624650.html
Copyright © 2011-2022 走看看