Error and Diagnostic Messages

spring3+hibernate4 service 中多线程事务异常及解决

初次使用spring3结合hibernate4做项目,迅速配置完成,测试,一切正常。

然而,当我在service层中另外开启一个线程,线程中的方法需要进行数据库操作,这个时候,悲催的抛出了异常:-org.hibernate.HibernateException: No Session found for current thread

当然,hibernate4的session是和当前线程绑定的,多线程中用sessionFactory.getCurrentSession()获取当前session自然不存在,不存在又不会自动创建,所以抛出了异常,无可厚非。

于是就想着怎么解决这个问题。

遍翻google、baidu,大部分都说如何如何配置,设置事务的传播属性propagation="REQUIRED",开启opensessioninview filter等等,无一对此问题有何解释(当然或许是我没翻到,有知道的麻烦告知)

在http://sishuok.com/forum/blogPost/list/2625.html#7523上看到相关配置,我就想作者这个项目该多线程运行正常吧,果断下载源码,修改测试,oh。。。跟我的错一模一样!

Баги и фичи

Уважаемые читатели и авторы русскоязычных блогов Сообщества Разработчиков Intel, с сентября 2012 года блоги работают на новой площадке - Intel Developer Zone (IDZ), используют новый "движок", дают новые возможности, и, к сожалению,.... новые баги. Так, в течение нескольких недель вместо русскоязычных блогов на соответствующей странице IDZ отображались блоги на английском языке, а RSS-подписчикам однажды даже довелось получить посты на китайском языке. Существуют проблемы и с отображением блогов и с их созданием. Хотя их число постепенно и неуклонно уменьшается, но пока оно больше нуля.

draft

This entity is not permitted in a specification expression.

This entity is not permitted in a specification expression.

Thank you for your interest in this diagnostic message.We are still in the process of documenting this specific diagnostic.

Please let us know of your experience with this diagnostic message by posting a comment below. Your interest in this diagnostic will help us prioritize the order we document diagnostics.

  • Linux*
  • Apple OS X*
  • Microsoft Windows* (XP, Vista, 7)
  • C/C++
  • Compilador C++ Intel®
  • Composer XE C++ Intel®
  • error
  • warning
  • remark
  • A variable in a blank common cannot be specified with the OFFLOAD:TARGET attribute.

    A variable in a blank common cannot be specified with the OFFLOAD:TARGET attribute.

    Thank you for your interest in this diagnostic message.We are still in the process of documenting this specific diagnostic.

    Please let us know of your experience with this diagnostic message by posting a comment below. Your interest in this diagnostic will help us prioritize the order we document diagnostics.

  • Linux*
  • Apple OS X*
  • Microsoft Windows* (XP, Vista, 7)
  • C/C++
  • Compilador C++ Intel®
  • Composer XE C++ Intel®
  • error
  • warning
  • remark
  • OpenMP* directive disabled via command line.

    OpenMP* directive disabled via command line.

    Thank you for your interest in this diagnostic message.We are still in the process of documenting this specific diagnostic.

    Please let us know of your experience with this diagnostic message by posting a comment below. Your interest in this diagnostic will help us prioritize the order we document diagnostics.

  • Linux*
  • Apple OS X*
  • Microsoft Windows* (XP, Vista, 7)
  • C/C++
  • Compilador C++ Intel®
  • Composer XE C++ Intel®
  • error
  • warning
  • remark
  • Specifying a VALUE attribute for an array is an extension of Standard Fxx.

    Specifying a VALUE attribute for an array is an extension of Standard Fxx.

    Thank you for your interest in this diagnostic message.We are still in the process of documenting this specific diagnostic.

    Please let us know of your experience with this diagnostic message by posting a comment below. Your interest in this diagnostic will help us prioritize the order we document diagnostics.

  • Linux*
  • Apple OS X*
  • Microsoft Windows* (XP, Vista, 7)
  • C/C++
  • Compilador C++ Intel®
  • Composer XE C++ Intel®
  • error
  • warning
  • remark
  • option '/ML[d]' has been replaced with '/MT[d]'

    option '/ML[d]' has been replaced with '/MT[d]'

    Thank you for your interest in this diagnostic message.We are still in the process of documenting this specific diagnostic.

    Please let us know of your experience with this diagnostic message by posting a comment below. Your interest in this diagnostic will help us prioritize the order we document diagnostics.

  • Linux*
  • Apple OS X*
  • Microsoft Windows* (XP, Vista, 7)
  • C/C++
  • Compilador C++ Intel®
  • Composer XE C++ Intel®
  • error
  • warning
  • remark
  • draft

    If INTO modifier appears in optional offload directive the STATUS clause must be explicitly specified.

    If INTO modifier appears in optional offload directive the STATUS clause must be explicitly specified.

    Thank you for your interest in this diagnostic message.We are still in the process of documenting this specific diagnostic.

    Please let us know of your experience with this diagnostic message by posting a comment below. Your interest in this diagnostic will help us prioritize the order we document diagnostics.

  • Linux*
  • Apple OS X*
  • Microsoft Windows* (XP, Vista, 7)
  • C/C++
  • Compilador C++ Intel®
  • Composer XE C++ Intel®
  • error
  • warning
  • remark
  • A procedure called in an OpenMP* TARGET region must have the DECLARE TARGET attribute.

    A procedure called in an OpenMP* TARGET region must have the DECLARE TARGET attribute.

    Thank you for your interest in this diagnostic message.We are still in the process of documenting this specific diagnostic.

    Please let us know of your experience with this diagnostic message by posting a comment below. Your interest in this diagnostic will help us prioritize the order we document diagnostics.

  • Linux*
  • Apple OS X*
  • Microsoft Windows* (XP, Vista, 7)
  • C/C++
  • Compilador C++ Intel®
  • Composer XE C++ Intel®
  • error
  • warning
  • remark
  • A procedure called by a procedure with the DECLARE TARGET attribute must have the DECLARE TARGET attribute.

    A procedure called by a procedure with the DECLARE TARGET attribute must have the DECLARE TARGET attribute.

    Thank you for your interest in this diagnostic message.We are still in the process of documenting this specific diagnostic.

    Please let us know of your experience with this diagnostic message by posting a comment below. Your interest in this diagnostic will help us prioritize the order we document diagnostics.

  • Linux*
  • Apple OS X*
  • Microsoft Windows* (XP, Vista, 7)
  • C/C++
  • Compilador C++ Intel®
  • Composer XE C++ Intel®
  • error
  • warning
  • remark
  • Assine o Error and Diagnostic Messages