我在一个项目上使用推土机,它工作正常,但过了一会儿,我执行的相同映射开始给我下一个异常:

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>


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

我正在使用推土机5.4.0(las稳定版)

最佳答案

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

JDK,BeanUtils和Dozer中存在错误,这些错误共同导致这种奇怪的行为。

当我在接口中定义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;
    }
}


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

10-05 19:07