简体   繁体   English

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

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

I migrated my spring boot version from 1.5 to 2.1.我将 spring 引导版本从 1.5 迁移到 2.1。 Now started using hibernate version 5.3.12 vs previously 5.0.12.现在开始使用 hibernate 版本 5.3.12 与之前的 5.0.12。 And now I am seeing lot of previously uncaught hibernate exceptions like:现在我看到很多以前未捕获的 hibernate 异常,例如:

On @OneToOne mapping annotation because Cascade type was missing:在 @OneToOne 映射注释上,因为缺少 Cascade 类型:

ERROR: update or delete on table violates foreign key constraint

On a @Test when I am trying to get a record by: repository.findById()当我试图通过以下方式获取记录时,在 @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. 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.

Tried to search on this but couldn't find anything specific about what changed in this hibernate version vs the previous ones.尝试对此进行搜索,但找不到任何关于此 hibernate 版本与以前版本相比发生了什么变化的具体内容。 Has anyone encountered similar issues?有没有人遇到过类似的问题? any help or hint would be much appreciated since I am stuck on these.任何帮助或提示将不胜感激,因为我坚持这些。

So, the reason of all of them that you try to serialize your objects out of Service layer.因此,您尝试将对象序列化到服务层之外的所有原因。 (Transactional annotation) (事务注解)

@Entity
class A {

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

If you try to serialize class A out of service layer, then hibernate session is already closed, and u have a mentioned exception如果您尝试序列化 class A out of service layer,那么 hibernate session 已经关闭,并且您有提到的异常

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

The correct way to fix it, is to assemble DTO (data transfer object) and return it from service layer to controller.修复它的正确方法是组装 DTO(数据传输对象)并将其从服务层返回到 controller。 And afterwards serialize DTO.然后序列化 DTO。

暂无
暂无

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

相关问题 在Spring Boot中从Hibernate迁移到EclipseLink - Migration from Hibernate to EclipseLink in Spring Boot RestTemplate / HttpClient更改了Spring Boot 1.5-> 2.1 - RestTemplate/HttpClient changes Spring Boot 1.5 -> 2.1 如何在从 1.5.x 到 2.1.x 的 spring boot 升级期间解决“检测到自动配置周期” - How to resolve "AutoConfigure cycle detected" during spring boot upgrade from 1.5.x to 2.1.x 在Spring Boot 2.1中覆盖Hibernate ConnectionProvider - Overriding Hibernate ConnectionProvider in Spring Boot 2.1 TestRestTemplate-从Spring Boot 1.5迁移到2.0 - TestRestTemplate - migrating from spring boot 1.5 to 2.0 Spring Boot JPA中的持久性和休眠错误 - persistence and Hibernate errors in spring boot JPA Spring Boot 3和Hibernate 6迁移报错:The conversion from datetime2 to DATETIMEOFFSET is unsupported - Spring Boot 3 and Hibernate 6 migration error: The conversion from datetime2 to DATETIMEOFFSET is unsupported 在将 Spring 启动 1.5 迁移到 2.1 后出现缺少 jaxb-runtime api 错误 - Getting Missing jaxb-runtime api error after Migrate Spring boot 1.5 to 2.1 从 spring 引导向后迁移到 spring 内核 - Backward migration from spring boot to spring core org.springframework.dao.DataIntegrityViolationException 使用 hibernate 和 spring-boot-data-jpa 将 spring-boot 从 2.1.x 更新到 2.2.x 后 - org.springframework.dao.DataIntegrityViolationException after update spring-boot from 2.1.x to 2.2.x using hibernate and spring-boot-data-jpa
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM