gpt4 book ai didi

java - 无法确定字段 : 'id' in Class in Dozer 的写入方法

转载 作者:行者123 更新时间:2023-12-01 13:27:55 28 4
gpt4 key购买 nike

我在一个项目上使用 Dozer,它工作得很好,但过了一会儿,我之前执行的相同映射开始给我下一个异常:

15:13:29,928 ERROR MappingProcessor:295 - Field mapping error -->
MapId: null
Type: null
Source parent class: org.persistencias.PP
Source field name: id
Source field type: class java.lang.Long
Source field value: 1
Dest parent class: org.dtos.PPDTO
Dest field name: id
Dest field type: java.lang.Long
org.dozer.MappingException: java.lang.NoSuchMethodException: Unable to determine write method for Field: 'id' in Class: class org.dtos.PPDTO
at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:82)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.invokeWriteMethod(GetterSetterPropertyDescriptor.java:280)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.setPropertyValue(GetterSetterPropertyDescriptor.java:102)
at org.dozer.fieldmap.FieldMap.writeDestValue(FieldMap.java:94)
at org.dozer.MappingProcessor.writeDestinationValue(MappingProcessor.java:895)
at org.dozer.MappingProcessor.mapFromFieldMap(MappingProcessor.java:349)
at org.dozer.MappingProcessor.mapField(MappingProcessor.java:288)
at org.dozer.MappingProcessor.map(MappingProcessor.java:248)
at org.dozer.MappingProcessor.map(MappingProcessor.java:197)
at org.dozer.MappingProcessor.map(MappingProcessor.java:187)
at org.dozer.MappingProcessor.map(MappingProcessor.java:124)
at org.dozer.MappingProcessor.map(MappingProcessor.java:119)
at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:120)
at org.server.ServiciosP.getTodasPP(ServiciosP.java:86)
at org.server.ServicioImpl.getTodasPP(ServicioImpl.java:7668)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: java.lang.NoSuchMethodException: Unable to determine write method for Field: 'id' in Class: class org.dtos.PPDTO
at org.dozer.propertydescriptor.JavaBeanPropertyDescriptor.getWriteMethod(JavaBeanPropertyDescriptor.java:47)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.invokeWriteMethod(GetterSetterPropertyDescriptor.java:278)
... 40 more
org.dozer.MappingException: java.lang.NoSuchMethodException: Unable to determine write method for Field: 'id' in Class: class org.dtos.PPDTO

但是我的 POJO 和 DTO 上有 id setter 方法。

POJO:

// Property accessors
@GenericGenerator(name = "generator", strategy = "increment")
@Id
@GeneratedValue(generator = "generator")
@Column(name = "id", unique = true, nullable = false)
public Long getId() {
return this.id;
}

public void setId(Long id) {
this.id = id;
}

DTO:

public Long getId() {
return this.id;
}

public void setId(Long id) {
this.id = id;
}

最后我的映射代码:

<mapping>
<class-a>org.persistencias.PP</class-a>
<class-b>org.dtos.PPDTO</class-b>
</mapping>

这里有人知道如何解决这个问题或指出问题根源吗?

我正在使用 dozer 5.4.0(最新稳定版本)

最佳答案

正如 GitHub 上本期所述,这似乎是不同库中错误的组合: https://github.com/DozerMapper/dozer/issues/118

JDK、BeanUtils 和 Dozer 中存在错误,这些错误结合起来会导致这种奇怪的行为。

当我在接口(interface)中定义 getter 并在类本身中实现 ​​setter 时,我遇到了同样的问题。

MyInterface.java

public interface MyInterface {
String getMe();
}

MyClass.java

public class MyClass implements MyInterface {

private String me;

@Override
public String getMe() {
return me;
}

public void setMe(String me) {
this.me = me;
}
}

要解决此问题,您需要在同一类或接口(interface)中定义 setter 和 getter。使用 JDK 8 时,这种情况也不应该发生。

关于java - 无法确定字段 : 'id' in Class in Dozer 的写入方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21712896/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com