映射异常:调用目标异常

发布于 2024-09-16 05:29:54 字数 1290 浏览 12 评论 0原文

我这里有一个小问题,希望有人可以帮助我。

我想做一个从对象到整数的映射。该对象被标记为 Fetchtype.Lazy。

当我进行映射时,我收到以下错误消息:

11:31:46,569 ERROR MappingProcessor:253 - Field mapping error -->
  MapId: null
  Type: null
  Source parent class: ClassA
  Source field name: MyObjectProperty
  Source field type: null
  Source field value: null
  Dest parent class: ClassB
  Dest field name: myIntegerProperty
  Dest field type: java.lang.Integer
org.dozer.MappingException: java.lang.reflect.InvocationTargetException
    at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:88)
    at org.dozer.util.ReflectionUtils.invoke(ReflectionUtils.java:258)
    at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.invokeReadMethod(GetterSetterPropertyDescriptor.java:234)
    at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.getPropertyValue(GetterSetterPropertyDescriptor.java:68)
    at org.dozer.fieldmap.FieldMap.getSrcFieldValue(FieldMap.java:82)

InnerException:

Caused by: java.lang.IllegalStateException: Attempt to access an unloaded field of detached instance

我在 dozer xml 文件中创建了一个自定义转换器,但从未调用该转换器。我猜想应用程序在到达此转换器之前会遇到问题。

有趣的是,我可以反过来成功映射字段,即整数到对象。

我很感激任何想法,如果您需要更多信息,请给我留言。

谢谢大家。

I have a small problem here and hope that someone can help me out.

I wanna do a mapping from Object to Integer. The Object is marked as Fetchtype.Lazy.

When I do the mapping I get the following error message:

11:31:46,569 ERROR MappingProcessor:253 - Field mapping error -->
  MapId: null
  Type: null
  Source parent class: ClassA
  Source field name: MyObjectProperty
  Source field type: null
  Source field value: null
  Dest parent class: ClassB
  Dest field name: myIntegerProperty
  Dest field type: java.lang.Integer
org.dozer.MappingException: java.lang.reflect.InvocationTargetException
    at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:88)
    at org.dozer.util.ReflectionUtils.invoke(ReflectionUtils.java:258)
    at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.invokeReadMethod(GetterSetterPropertyDescriptor.java:234)
    at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.getPropertyValue(GetterSetterPropertyDescriptor.java:68)
    at org.dozer.fieldmap.FieldMap.getSrcFieldValue(FieldMap.java:82)

InnerException:

Caused by: java.lang.IllegalStateException: Attempt to access an unloaded field of detached instance

I created a custom converter in dozer xml file but the converter is never called. I guess the application gets a problem before reaching this converter.

Funny thing is I can Map the fields successfully the other way around, so Integer to Object.

I appreciate any ideas, if you need further information please give me a word.

Thx to all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

马蹄踏│碎落叶 2024-09-23 05:29:54

如果这是 Hibernate,我会认为在数据 bean 绑定到的会话之外访问了延迟加载的字段。

我建议加载实体并将其映射到同一事务中可以解决问题。我当然不确定:)

If this were Hibernate I'd think a lazily loaded field were accessed outside of the Session the data bean is bound to.

I suggest loading the entity and mapping it in the same transaction would solve the problem. I don't know that for sure of course :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文