当我使用Error命中一个端点时,我收到以下错误,我有两个类,其中一个是实体,另一个是视图。
Error accessing field [private long com.ge.power.brs.domains.PartOperation.id] by reflection for persistent property [com.ge.power.brs.domains.PartOperation#id] : PartOperationView{id=2969, operationOrder=1, name='Rec & ID', code='0011', status=PENDING, comment='', operationId=2', partTagNo=0', skippedOperations=null', formData=null}; nested exception is org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private long com.ge.power.brs.domains.PartOperation.id] by reflection for persistent property [com.ge.power.brs.domains.PartOperation#id] : PartOperationView{id=2969, operationOrder=1, name='Rec & ID', code='0011', status=PENDING, comment='', operationId=2', partTagNo=0', skippedOperations=null', formData=null}
我有两个班级:
@Table(name = "part_operations", schema = "brs")
@Entity
public class PartOperation implements Serializable {
private static final long serialVersionUID = 1;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@Column(name = "part_id")
private long partId;
@Column(name = "operation_id")
private long operationId;
public class PartOperationView {
private long id;
private long operationOrder;
private String name;
private String code;
private OperationStatus status;
private String comment;
private String operationId;
private long partTagNo;
private Map<String, Object> formData;
private List<PartOperationView> skippedOperations;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getOperationOrder() {
return operationOrder;
}
本地服务器出错:
2016-12-12 16:33:46.705[0;39m [31mERROR[0;39m [35m47144[0;39m [2m---[0;39m [2m[nio-9000-exec-1][0;39m [36mo.a.c.c.C.[.[.[/].[dispatcherServlet] [0;39m [2m:[0;39m Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Error accessing field [private long com.ge.power.brs.domains.PartOperation.id] by reflection for persistent property [com.ge.power.brs.domains.PartOperation#id] : PartOperationView{id=2969, operationOrder=1, name='Rec & ID', code='0011', status=PENDING, comment='', operationId=2', partTagNo=0', skippedOperations=null', formData=null}; nested exception is org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private long com.ge.power.brs.domains.PartOperation.id] by reflection for persistent property [com.ge.power.brs.domains.PartOperation#id] : PartOperationView{id=2969, operationOrder=1, name='Rec & ID', code='0011', status=PENDING, comment='', operationId=2', partTagNo=0', skippedOperations=null', formData=null}] with root cause
java.lang.IllegalArgumentException: Can not set long field com.ge.power.brs.domains.PartOperation.id to com.ge.power.brs.core.views.PartOperationView
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
at sun.reflect.UnsafeLongFieldAccessorImpl.getLong(UnsafeLongFieldAccessorImpl.java:60)
at sun.reflect.UnsafeLongFieldAccessorImpl.get(UnsafeLongFieldAccessorImpl.java:36)
at java.lang.reflect.Field.get(Field.java:393)
at org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:39)
以下是转换器代码:
@Override
public PartOperationView convertToView(PartOperation partOperation) {
if (partOperation == null) {
return null;
}
PartOperationView partOperationView = new PartOperationView();
BeanUtils.copyProperties(partOperation, partOperationView);
// operation id is a required field and should always exists, so we won't check for null
long operationId = partOperation.getOperationId();
partOperationView.setOperationId(String.valueOf(operationId));
if (partOperation.getFormData() != null) {
try {
TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() { };
partOperationView.setFormData(objectMapper.readValue(partOperation.getFormData(), typeRef));
} catch (IOException e) {
throw new IllegalArgumentException("The form data field is not in the correct format.", e);
}
}
return partOperationView;
}