繁体   English   中英

spring 引导从 1.5 迁移到 2.1,hibernate 错误

[英]spring boot migration from 1.5 to 2.1, hibernate errors

我将 spring 引导版本从 1.5 迁移到 2.1。 现在开始使用 hibernate 版本 5.3.12 与之前的 5.0.12。 现在我看到很多以前未捕获的 hibernate 异常,例如:

在 @OneToOne 映射注释上,因为缺少 Cascade 类型:

ERROR: update or delete on table violates foreign key constraint

当我试图通过以下方式获取记录时,在 @Test 上:repository.findById()

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

on old project with hibernate 5.0.12 these errors don't appear, but as soon as I switch to new spring boot project, these start appearing with the only change factor being upgraded spring dependencies and hibernate version.

尝试对此进行搜索,但找不到任何关于此 hibernate 版本与以前版本相比发生了什么变化的具体内容。 有没有人遇到过类似的问题? 任何帮助或提示将不胜感激,因为我坚持这些。

因此,您尝试将对象序列化到服务层之外的所有原因。 (事务注解)

@Entity
class A {

   @OneToOne(fetch = FetchType.LAZY)
   private B b;
}

如果您尝试序列化 class A out of service layer,那么 hibernate session 已经关闭,并且您有提到的异常

检查这个https://www.baeldung.com/hibernate-lazy-eager-loading

修复它的正确方法是组装 DTO(数据传输对象)并将其从服务层返回到 controller。 然后序列化 DTO。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM