org.hibernate.LazyInitializationException: could not initialize proxy - no Session
来源:互联网 发布:focusky 3.7破解版mac 编辑:程序博客网 时间:2024/05/17 06:15
先在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>
具体的类
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.hibernate.SessionFactory;
import org.springframework.context.ApplicationContext;
public class MyOpenSessionInViewFilter implements Filter {
private ApplicationContext context=null;
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws IOException, ServletException {
SessionFactory factory=(SessionFactory) context.getBean("SessionFactory");
factory.getCurrentSession().beginTransaction();
try{
chain.doFilter(req, resp);
factory.getCurrentSession().beginTransaction().commit();
}catch(Exception e){
factory.getCurrentSession().beginTransaction().rollback();
}
factory.getCurrentSession().close();
}
@Override
public void init(FilterConfig config) throws ServletException {
Object o=config.getServletContext().getAttribute("org.springframework.web.context.WebApplicationContext.ROOT");
System.out.println(o.getClass().getName());
this.context=(ApplicationContext) o;
}
}
0 0
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- error:org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- 异常: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- Linux学习之数值运算与运算符
- 15 条实用 Linux/Unix 磁带管理命令
- 利用Openvswitch实现不同物理机中的Docker容器互连
- BRIDGE(桥接模式)
- his跟hrp的区别
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- 死锁的产生、预防、以及接触方法整理,一目了然
- maven打包jar包重复问题分析
- [剑指offer]序列化二叉树
- app系统签名
- 20150416指针
- wifi开关常用广播以及监听状态改变
- Nginx安装与配置文件解析
- jsp实现textarea中的文字保存换行空格存到数据库