Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 使用Completable Future使用Spring数据从DB获取数据时的奇怪行为_Spring Boot_Hibernate_Spring Data Jpa_Completable Future - Fatal编程技术网

Spring boot 使用Completable Future使用Spring数据从DB获取数据时的奇怪行为

Spring boot 使用Completable Future使用Spring数据从DB获取数据时的奇怪行为,spring-boot,hibernate,spring-data-jpa,completable-future,Spring Boot,Hibernate,Spring Data Jpa,Completable Future,当使用CompletebleFuture从Spring数据存储库获取数据时,我注意到一个奇怪的行为。使用正常方式获取数据与使用CompletableFuture不同 区别如下: 使用CompletableFuture检索的数据 正常检索数据 我的代码如下所示: 这里我的问题是,当我使用CompletableFuture时,为什么它无法获取customGroups信息?它为customGroup fetch引发LazyInitializationException异常。在用户实体内部,其定义

当使用CompletebleFuture从Spring数据存储库获取数据时,我注意到一个奇怪的行为。使用正常方式获取数据与使用CompletableFuture不同

区别如下:

使用CompletableFuture检索的数据

正常检索数据

我的代码如下所示:

这里我的问题是,当我使用CompletableFuture时,为什么它无法获取customGroups信息?它为customGroup fetch引发LazyInitializationException异常。在用户实体内部,其定义为Set,而不是List和fetchtype-EAGER

此代码在正常或同步调用时按预期工作


有人能解释为什么两个线程之间的行为发生了变化吗?

会话只在一个线程中打开,将来您将使用多个线程,并且基础会话(可能)不再可用于检索其他线程(延迟)data.@M.Deinum有没有办法使会话多线程化?以编程方式搜索“spring open transaction”并从那里开始需要多少钱?@Eugene great lead,让我检查一下