模型映射器中的延迟初始化异常

编程入门 行业动态 更新时间:2024-10-11 11:20:24
本文介绍了模型映射器中的延迟初始化异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在从实体转换为dto时,Modelmapper提供LazyInitializationException.

Modelmapper is giving LazyInitializationException while converting from entity to dto.

有什么办法可以禁用此功能吗?如果在事务块内调用modelmapper.map,它工作正常,但它正在加载我根本不需要的所有惰性对象. 我要是懒惰就根本不要加载它.

Is there any way i can disable this. If am calling modelmapper.map inside transaction block it is working fine but it is loading all my lazy objects which i dont want at all. I want if lazy then do not load it at all.

转换器org.modelmapper.internal.converter.MergingCollectionConverter@6a51c12e无法将org.hibernate.collection.internal.PersistentSet转换为java.util.Set.

Converter org.modelmapper.internal.converter.MergingCollectionConverter@6a51c12e failed to convert org.hibernate.collection.internal.PersistentSet to java.util.Set.

由以下原因引起:org.modelmapper.MappingException:ModelMapper映射错误:

Caused by: org.modelmapper.MappingException: ModelMapper mapping errors:

1)无法从com.app.flashdiary.entity.Vendor.getApproved()

原因:org.hibernate.LazyInitializationException:无法初始化代理[com.app.flashdiary.entity.Vendor#1]-没有会话 在org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:169)

Caused by: org.hibernate.LazyInitializationException: could not initialize proxy [com.app.flashdiary.entity.Vendor#1] - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:169)

推荐答案

我从这里找到了解决方案:

I found the solution from here:

github/modelmapper/modelmapper/issues/97

modelMapper.getConfiguration().setPropertyCondition(new Condition<Object, Object>() { public boolean applies(MappingContext<Object, Object> context) { return !(context.getSource() instanceof PersistentCollection); } });

更多推荐

模型映射器中的延迟初始化异常

本文发布于:2023-10-18 15:14:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504605.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   模型   器中   异常

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!