cannot simultaneously fetch multiple bags

问题描述:

项目中有多个一对多的数据结构,多个一对多注解设置fetch = FetchType.EAGER就会出现这个启动报错:

@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval = true, fetch = FetchType.EAGER)

解决方案:

1.使用@Fetch(FetchMode.SUBSELECT)注解。
仍然报错:

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role,could not initialize proxy - no Session

2.配置文件添加enable_lazy_load_no_trans注解。

spring:
  jpa:
    properties:
      hibernate:
        enable_lazy_load_no_trans: true

注解设置为true,没有事务的情况下允许懒加载,服务就能正常运行了!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Navicat Premium is a multi-connections database administration tool allowing you to connect to MySQL, SQL Server, SQLite, Oracle and PostgreSQL databases simultaneously within a single application, making database administration to multiple kinds of database so easy. Navicat Premium combines the functions of other Navicat members and supports most of the features in MySQL, SQL Server, SQLite, Oracle and PostgreSQL including Stored Procedure, Event, Trigger, Function, View, etc. Navicat Premium enables you to easily and quickly transfer data across various database systems, or to a plain text file with designated SQL format and encoding. Also, batch job for different kind of databases can also be scheduled and run at a specific time. Other features include Import/ Export Wizard, Query Builder, Report Builder, Data Synchronization, Backup, Job Scheduler and more. Features in Navicat are sophisticated enough to provide professional developers for all their specific needs, yet easy to learn for users who are new to database server. Here are some key features of "Navicat Premium": · Secure Connection · Object Designer · Table Viewer · SQL Builder/Editor · Database Designer · PL/SQL Code Debugger · Report Builder/Viewer Data Manipulation Tools: · Import/Export Wizard · Data Transfer · Data/Structure Synchronization · Backup/Restore · Schedule Useful Tools: · ER diagram · Connection coloring/Virtual grouping · Tree/object filter · Favorites OS : Microsoft Windows XP SP2, Vista, Windows 7, Windows 8, Server 2003, Server 2008, Server 2012 Language : English

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值