HibernateException: Could not obtain transaction-synchronized Session for current thread 的解决方法。
来源:互联网 发布:淘宝网面条机 编辑:程序博客网 时间:2024/05/03 18:11
代码执行到 Query q = getSession().createQuery(“hql”); 没有报错,但是不再往下执行了。
尝试try catch。
try {
getSession();
} catch (Exception e) {
e.printStackTrace();
}
控制台报错。
HibernateException: Could not obtain transaction-synchronized Session for current thread。
解决方法:在该方法上添加@Transactional注解之后,可以顺利执行。
百度还有另外的解决方法,在web.xml 中添加过滤器。
<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
不过这种方法并没有解决我的问题。
0 0
- HibernateException: Could not obtain transaction-synchronized Session for current thread 的解决方法。
- HibernateException: Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread解决方法
- 多线程出现HibernateException: Could not obtain transaction-synchronized Session for current thread
- 【Hibernate】Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- 安卓检查APP是否被用户拒绝调用摄像头和麦克风权限
- JQuery_HighCharts 图像导出 以及打印
- HTML的头部标签/ HTML5 head meta
- Oralce SQLPlus 以及shell脚本中spool输出到文件时的格式化输出
- 欢迎使用CSDN-markdown编辑器
- HibernateException: Could not obtain transaction-synchronized Session for current thread 的解决方法。
- 手链样式 --蓝桥杯
- android private libraries 添加源码
- Spring MVC里面的预防 SQL 注入
- Android:RecyclerView详解(ListView,GirdView,瀑布流)
- Oracle 数据导出工具 Spool
- C++虚继承(七) --- 虚继承对基类构造函数调用顺序的影响
- 使用库函数API和C代码中嵌入汇编代码两种方式使用同一个系统调用
- 静态链表的实现