【视频&交流平台】
http://study.163.com/course/introduction.htm?courseId=1004329008&utm_campaign=commission&utm_source=400000000155061&utm_medium=share
http://study.163.com/course/introduction.htm?courseId=1004638001&utm_campaign=commission&utm_source=400000000155061&utm_medium=share
https://gitee.com/happyangellxq520/spring-boot
http://412887952-qq-com.iteye.com/blog/2321532
【原创文章,转载请注明出处】
Spring与JPA结合时,如何解决懒加载no session or session was closed!!!
实际上Spring Boot是默认是打开支持session view filter的,所以大家正常应该是不会发现有这个问题的,但是还是有人提出了,好吧,如果真的碰到的话,那么可以按照如下尝试解决下。
我们先看看有这么几个类(省略一些代码,只提供核心的):
Teacher:
@Entity
public class Teacher {
@Id @GeneratedValue
private long id;
private String teaName;
}
Student:
@Entity
public class Student {
@Id@GeneratedValue
private long id;
private String stuName;
@ManyToOne(fetch = FetchType.LAZY)
private Teacher classTeacher;
}
StudentRepository:
public interface StudentRepository extends CrudRepository<Student,Long>{
}
访问控制器:
@RequestMapping("/hello")
public String hello(Map<String,Object> map){
map.put("student",studentRepository.findOne(1L));
return "/hello";
}
访问/hello那么如果出现如下异常信息:
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
那么可以这是由于我们使用懒加载加载数据的方法,当我们要获取的数据的时候,但是session已经关闭了,我们支持在Spring MVC中需要配置一个OpenEntityManagerInViewFilter 过滤器,Spring针对Hibernate的非JPA实现用的是OpenSessionInViewFilter,那么在Spring Boot中怎么支持呢?
特别特别的简单,只需要在application.properties中加入如下配置:
spring.jpa.open-in-view=true
这么一个配置即可支持,默认这个值就为true。
【Spring Boot 系列博客】
视频&交流平台:
http://study.163.com/course/introduction.htm?courseId=1004329008
http://412887952-qq-com.iteye.com/blog/2321532
网易云课堂视频最新更新:
第十一章 Spring Boot 日志
1、spring boot日志—理论
2、Spring Boot日志-logback
3、Spring Boot日志-log4j2
第十二章 Spring Boot 知识点2
1、spring boot 服务配置和部署
2、Spring Boot 定制URL匹配规则
历史章节:
第一章 快速开始
1、Spring Boot之Hello World
2、Spring Boot之Hello World访问404
第二章 Spring Boot之JSON
1、spring boot返回json数据
2、Spring Boot完美使用FastJson解析JSON数据
第三章 Spring Boot热部署
1、Spring Boot热部署(springloader)
2、springboot + devtools(热部署)
第四章 Spring Boot数据库
1、Spring Boot JPA/Hibernate/Spring Data概念
2、Spring Boot JPA-Hibernate
3、Spring Boot Spring Data JPA介绍
4、Spring Boot JdbcTemplate
5、Spring Boot集成MyBatis
第五章 web开发
1、全局异常捕捉
2、配置server信息
3、spring boot使用thymeleaf
4、Spring Boot 使用freemarker
5、Spring Boot添加JSP支持
第六章 定时任务
1、Spring Boot定时任务
2、Spring Boot 定时任务升级篇(动态修改cron参数)
3、Spring Boot 定时任务升级篇(动态添加修改删除定时任务)
4、Spring Boot 定时任务升级篇(集群/分布式下的定时任务说明)
5、Spring Boot Quartz介绍
6、Spring Boot Quartz在Java Project中使用
7、Spring Boot 集成Quartz普通使用
8、Spring Boot 集成Quartz升级版
9、Spring Boot 集成Quartz二次升级版
10、Spring Boot 集成Quartz-Job如何自动注入Spring容器托管的对象
第七章 Spring Boot MyBatis升级篇
1、Spring Boot MyBatis升级篇-注解
2、Spring Boot MyBatis升级篇-注解-自增ID
3、Spring Boot MyBatis升级篇-注解-增删改查
4、Spring Boot MyBatis升级篇-注解-分页查询
5、Spring Boot MyBatis升级篇-注解-分页PageHelper不生效
6、Spring Boot MyBatis升级篇-注解- mybatic insert异常:BindingException: Parameter 'name' not found
7、Spring Boot MyBatis升级篇-注解- #和$符号特别篇
8、Spring Boot MyBatis升级篇-注解-@Result
9、Spring Boot MyBatis升级篇-注解-动态SQL(if test)-方案一:<script>
10、Spring Boot MyBatis升级篇-注解-动态SQL(if test)-方案二:@Provider
11、Spring Boot MyBatis升级篇-注解-动态SQL-参数问题
12、Spring Boot MyBatis升级篇-注解-特别篇:@MapperScan和@Mapper
13、Spring Boot MyBatis升级篇-XML
14、Spring Boot MyBatis升级篇-XML-自增ID
15、Spring Boot MyBatis升级篇-XML-增删改查
16、Spring Boot MyBatis升级篇-XML-分页查询
17、Spring Boot MyBatis升级篇-XML-分页PageHelper不生效
18、Spring Boot MyBatis升级篇-XML-动态SQL(if test)
19、Spring Boot MyBatis升级篇-XML-注解-初尝试
20、Spring Boot MyBatis升级篇- pagehelper替换为pagehelper-spring-boot-starter
第八章 Spring Boot 知识点1
1、Spring Boot 拦截器HandlerInterceptor
2、Spring Boot启动加载数据CommandLineRunner
3、Spring Boot环境变量读取和属性对象的绑定
4、Spring Boot使用自定义的properties
5、Spring Boot使用自定义的properties
6、Spring Boot使用@SpringBootApplication
7、Spring Boot 监控和管理生产环境
第十章 Spring Boot 打包部署
1、Spring Boot打包部署((提供Linux的sh文件))
第十一章 Spring Boot 日志
1、spring boot日志—理论
2、Spring Boot日志-logback
3、Spring Boot日志-log4j2
相关推荐
当你尝试在Controller层或者视图层访问懒加载的属性时,如果Session已经关闭("no Session..."错误),就会抛出`org.hibernate.LazyInitializationException`。这是因为懒加载的代理对象需要Session来执行数据库查询...
标题 "Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser" 提示了一个Java运行时错误,这通常意味着在尝试加载或初始化`JRStyledTextParser`类时遇到了问题。`JRStyledTextParser`是...
Spring Boot Documentation 1. About the Documentation 2. Getting Help 3. First Steps 4. Working with Spring Boot 5. Learning about Spring Boot Features 6. Moving to Production 7. Advanced Topics II. ...
在使用PL/SQL Developer 12连接Oracle数据库时,可能会遇到“Could not initialize oci.dll”这样的错误提示。这个错误通常表明系统无法找到或正确加载Oracle客户端的oci.dll库文件,这是Oracle Instant Client的一...
mysqld --initialize 初始化 chown mysql:mysql /var/lib/mysql -R 授权 systemctl start mysqld 开启mysql服务 systemctl status mysqld 查看mysql 状态 cat /var/log/mysqld.log | grep password 查看root初始...
sudo mysql-8.0.20-el7-x86_64/bin/mysqld --initialize-insecure ``` ### 启动MySQL服务 1. **启动MySQL**:执行以下命令启动MySQL服务。 ```bash sudo mysql-8.0.20-el7-x86_64/bin/mysqld_safe --user=mysql &...
org.apache.poi:poi:4.1.2 org.apache.poi:poi-ooxml:4.1.2 org.apache.poi:poi-ooxml-schemas:4.1.2 org.apache.xmlbeans:xmlbeans:3.1.0 ...commons-codec:commons-codec:1.13 org.apache.commons:commons-...
2.2.3.1+spring-framework-3.1.0+hibernate-distribution-3.6.8+JSON+MySQL+Annotation,并且对Dao和Service进行了封装,内含.jar包,并且解决了一对多双向关联的could not initialize proxy - no Session错误,同时...
内涵jacob_1.14.3-x64.dll;jacob_1.14.3-64.jdk(maven地址);解决方法:Could not initialize class com.jacob.com.ComThread
1. `<jdbc:initialize-database>`:用于自动初始化数据库,例如创建表、填充数据等,常在测试环境中使用。 2. `<jdbc:embedded-database>`:创建一个内存中的数据库,通常用于单元测试,如HSQLDB或Derby。 3. `...
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION ``` 5. 初始化 MySQL: - 安装依赖:`yum install libaio* -y` - 初始化数据库:`cd /usr/...
为了解决spring整合cxf,xfire遇到的jar包冲突问题,将XmlSchema.1.1.1.jar和xfire-all1.2.6.jar修改后进行了重新编译打包
解决:oracle_plsql连服务端时 Initialization error could initialize错误处理方法
iText是一款广泛使用的Java库,专门用于创建、编辑和处理PDF文档。这个压缩包包含了两个主要的JAR文件:`itext-asian-5.2.0.jar`和`itextpdf-5.5.13.1.jar`,它们在处理PDF文件时扮演着重要的角色。...
hbase Could not initialize class org.fusesource.jansi.internal.Kernel32; 可能是因为windows下缺jansi-1.4.jar ;解决方案:下载jansi-1.4.jar包放到hbase-2.2.1\lib下,重新启动即可
Cannot initialize the monitoring on 192.168.52.189. Error while creating the RPC client. Ensure that the machine can be connected and that it runs the rstat daemon (use rpcinfo utility for this ...
由于找不到vcruntime140_1.dll,无法继续执行代码。解决方法:将缺失的文件`vcruntime140_1.dll`复制到C:\Windows\System32目录下(32位操作系统需复制到C:\Windows\SysWOW64)即可解决。
监听COM口启动程序报错 Could not initialize class gnu.io.RXTXCommDriver异常 是因为需要在%JAVA_HOME%/jre/bin目录中添加rxtxParallel.dll、rxtxSerial.dll文件
【Spring Boot 概述】 Spring Boot 是一个由 Pivotal 团队开发的 Java 框架,旨在简化 Spring 应用程序的初始搭建以及开发过程。它通过提供默认配置来消除大量的样板代码,使开发者可以更快速地构建可运行的项目。...
解决hbase client在windows环境下报Could not initialize class org.fusesource.jansi.internal.Kernel32的问题,把jar包放入hbase client的lib包下,重新运行hbase.cmd shell即可