栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

问题修复 No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

问题修复 No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor

报错详情
org.springframework.data.redis.serializer.SerializationException: Could not write JSON: No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: 
xx.xx.xx.xx.xx.XXX$HibernateProxy$KnxukjCm["$$_hibernate_interceptor"]); nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: 
xx.xx.xx.xx.xx.XXX$HibernateProxy$KnxukjCm["$$_hibernate_interceptor"])
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: 
xx.xx.xx.xx.xx.XXX$HibernateProxy$KnxukjCm["$$_hibernate_interceptor"])
问题分析 ①条件:

使用了JPA的Repository的getOne()方法。

②过程:

getOne()方法是一个延迟加载操作。只能获得对实体的引用(代理),实际上没有进行数据库访问。只有当调用它的属性时才会查询数据库。

解决方案① (推荐)

使用findById()方法来获取一个真实的实体。

解决方案②

在延时加载相关的字段上或者在实体类上加入相关注解忽略

@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
解决方案③

或者在延时加载的字段上修改延时加载属性

FetchType.LAZY

改为

FetchType.EAGER

表示急加载立即加载

如果文章对您有帮助,请扫红包码赞助

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/343478.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号