[英]org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role:ticketCircuitInfo, could not initialize proxy - no Session
I have 2 bean classes( ticketEntity
, ticketCircuitInfo
) mapped to 1 table each 我有2个bean类(
ticketEntity
, ticketCircuitInfo
)分别映射到1个表
I also have 1 ticketEntity(primary key)
that can have multiple ticketCircuitInfo(forign key)
我也有1个
ticketEntity(primary key)
,可以有多个ticketCircuitInfo(forign key)
The ticketEntity
bean has the following properties: ticketEntity
bean具有以下属性:
@Id
@Column(name = "ticket_id", unique = true, nullable = false)
private String ticketId;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "ticket", cascade =CascadeType.ALL)
private Set<TicketCircuitInfo> ticketCircuitInfo;
The ticketCircuitInfo bean has the following properties: ticketCircuitInfo bean具有以下属性:
@GenericGenerator(name = "generator", strategy = "foreign",
parameters = @Parameter(name = "property", value = "ticket"))
@Id
@Column(name = "ticket_id", unique = true, nullable = false)
private String ticketId;
@ManyToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
private TicketEntity ticket;`
I'm getting: 我越来越:
com.sun.jdi.InvocationException occurred invoking method.
com.sun.jdi.InvocationException发生了调用方法。
While debugging on the line ticket.ticketCircuitInfo()
. 在行上进行调试
ticket.ticketCircuitInfo()
。
further exception being printed is: 正在打印的另一个例外是:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role:ticketCircuitInfo, could not initialize proxy - no Session
org.hibernate.LazyInitializationException:无法延迟初始化role:ticketCircuitInfo的集合,无法初始化代理-没有会话
You should look into your service layer and add @Transactional to the service layer method.. 您应该查看服务层,并将@Transactional添加到服务层方法。
Please refer to : How to solve the “failed to lazily initialize a collection of role” Hibernate exception 请参考: 如何解决“无法延迟初始化角色集合”的Hibernate异常
You can change from 您可以从
@ManyToOne(fetch = FetchType.LAZY)
to 至
@ManyToOne(fetch = FetchType.EAGER)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.