Hibernate related
2015-09-21 20:37
127 查看
1. Cannot get .currentSession()
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:622)
@Override public void refreshObject() { Test test1; test1 = testDaoLocator.findById("1"); System.out.println("C1: " + test1.getC2()); test1.setC2("ddd"); } public Test findById(String id) { Test instance = (Test) this.getSessionFactory().getCurrentSession().get(Test.class, id); return instance; }
Cause:
There is no any session.
Solution 1 is using "this.getSessionFactory().openSession()" intead.
Solution 2 is adding transaction between the method like below:
<aop:config> <aop:advisor pointcut="execution(* lin.service..refreshObject(..))" advice-ref="requiresNewTxAdvice" /> </aop:config> <tx:advice id="requiresNewTxAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" propagation="REQUIRES_NEW" /> </tx:attributes> </tx:advice>
2.
阅读更多相关文章推荐
- CYC-集合视图 UICollectionView的简单使用
- 黑马程序员_java 操作文件的扩展,制作excel表格
- js判断是否定义
- 《程序员面试金典》--分割链表
- java中创建对象的方法
- Microsoft Dynamics CRM 2013 联系人 介绍
- Microsoft Dynamics CRM 2013 联系人 介绍
- poj--1256
- Java 多线程常用概念
- 下拉刷新效果
- 这是下一个伟大的公司
- Android请求网络共通类——Hi_博客 Android App 开发笔记
- java中的堆、栈和常量池
- Java 字符串
- leetcode之Add Digits
- iOS App键盘第一次启动延迟问题
- hdu2795Billboard【线段树】
- Remove advertisement of Storm 5
- message_flood
- 欢迎使用CSDN-markdown编辑器