xml - JAXBException 发生 : class javax. jdo.identity.LongIdentity 及其任何父类(super class)在此上下文中均未知

标签 xml rest jaxb annotations bind

客户端代码如下所示:

String urlGetRequestsByCustomer = baseUrl + "getRequestsByCustomer?customerID=";

byte[] getRequestsByCustomerResponse = customerAgent
.sendGetMethod(urlGetRequestsByCustomer + custNo);
Unmarshaller unmarshaller = customerAgent
.getUnmarshaller(ServiceRequests.class);
 StringReader reader = new StringReader(new String(
getRequestsByCustomerResponse));

ServiceRequests.java

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class ServiceRequests {


@XmlElement(name = "serviceRequest", type = ServiceRequest.class)
private List<ServiceRequest> requests = new ArrayList<ServiceRequest>();

/**
 * 
 */
public ServiceRequests() {
}

public ServiceRequests(List<ServiceRequest> requests) {
    this.requests = requests;
}

/**
 * @return the requests
 */
public List<ServiceRequest> getRequests() {
    return requests;
}

/**
 * @param requests
 *            the requests to set
 */
public void setRequests(List<ServiceRequest> requests) {
    this.requests = requests;
}

}

ServiceRequest.java

@Entity
@Table(name="SERVICE_REQUEST", uniqueConstraints = {@UniqueConstraint(columnNames=
{"SRNO"})})
@SequenceGenerator(name="SERVICE_REQUEST_SEQUENCE",     
sequenceName="SERVICE_REQUEST_SEQUENCE", initialValue=1, allocationSize=100)
@NamedQueries({
@NamedQuery(name="serviceRequest.getBySrNo",query="SELECT request from ServiceRequest 
request WHERE request.srNo = :srNo")
})

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class ServiceRequest implements Serializable {

private static final long serialVersionUID = 5047875961706019225L;

@Id @GeneratedValue(strategy=GenerationType.SEQUENCE, 
generator="SERVICE_REQUEST_SEQUENCE")
@Column(name="SRNO",  nullable=false)
private Long srNo;

@Column(name="DESCRIPTION")
private String description;

@Column(name="STATUS") 
private int status;


@ManyToOne(fetch=FetchType.EAGER , cascade=CascadeType.DETACH)
@JoinColumn(name="CUSTNO", referencedColumnName="CustNO")
private Customer customer;

@Column(name="DATECREATED")
private Date dateCreated;

@Column(name="DATEUPDATED")
private Date dateUpdated;

@Column(name="UPDATEDBY")
@ManyToOne(fetch=FetchType.LAZY, cascade=CascadeType.DETACH)
@JoinColumn(name="updatedBy")
private Employee updatedBy;

public Employee getUpdatedBy() {
    return updatedBy;
}


public void setUpdatedBy(Employee updatedBy) {
    this.updatedBy = updatedBy;
}


@OneToOne(fetch=FetchType.LAZY, mappedBy="serviceRequest", 
cascade=CascadeType.DETACH)
private CustomerSurvey survey;


/**
 * @return the dateUpdated
 */
public Date getDateUpdated() {
    return dateUpdated;
}


/**
 * @param dateUpdated the dateUpdated to set
 */
public void setDateUpdated(Date dateUpdated) {
    this.dateUpdated = dateUpdated;
}


/**
 * @return the survey
 */
public CustomerSurvey getSurvey() {
    return survey;
}


/**
 * @param survey the survey to set
 */
public void setSurvey(CustomerSurvey survey) {
    this.survey = survey;
}

public ServiceRequest() {
}


/**
 * @return the srNo
 */
public Long getSrNo() {
    return srNo;
}

/**
 * @param srNo the srNo to set
 */
public void setSrNo(Long srNo) {
    this.srNo = srNo;
}

/**
 * @return the description
 */
public String getDescription() {
    return description;
}

/**
 * @param description the description to set
 */
public void setDescription(String description) {
    this.description = description;
}

/**
 * @return the status
 */
public int getStatus() {
    return status;
}

/**
 * @param status the status to set
 */
public void setStatus(int status) {
    this.status = status;
}

/**
 * @return the customer
 */
public Customer getCustomer() {
    return customer;
}

/**
 * @param customer the customer to set
 */
public void setCustomer(Customer customer) {
    this.customer = customer;
}

/**
 * @return the dateCreated
 */
public Date getDateCreated() {
    return dateCreated;
}

/**
 * @param dateCreated the dateCreated to set
 */
public void setDateCreated(Date dateCreated) {
    this.dateCreated = dateCreated;
}

/* (non-Javadoc)
 * @see java.lang.Object#hashCode()
 */
@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result
            + ((dateCreated == null) ? 0 : dateCreated.hashCode());
    result = prime * result
            + ((dateUpdated == null) ? 0 : dateUpdated.hashCode());
    result = prime * result
            + ((description == null) ? 0 : description.hashCode());
    result = prime * result + (int) (srNo ^ (srNo >>> 32));
    result = prime * result + status;
    return result;
}

/* (non-Javadoc)
 * @see java.lang.Object#equals(java.lang.Object)
 */
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj == null) {
        return false;
    }
    if (!(obj instanceof ServiceRequest)) {
        return false;
    }
    ServiceRequest other = (ServiceRequest) obj;
    if (dateCreated == null) {
        if (other.dateCreated != null) {
            return false;
        }
    } else if (!dateCreated.equals(other.dateCreated)) {
        return false;
    }
    if (dateUpdated == null) {
        if (other.dateUpdated != null) {
            return false;
        }
    } else if (!dateUpdated.equals(other.dateUpdated)) {
        return false;
    }
    if (description == null) {
        if (other.description != null) {
            return false;
        }
    } else if (!description.equals(other.description)) {
        return false;
    }
    if (srNo != other.srNo) {
        return false;
    }
    if (status != other.status) {
        return false;
    }
    return true;
}

/* (non-Javadoc)
 * @see java.lang.Object#toString()
 */
@Override
public String toString() {
    return "ServiceRequest [srNo=" + srNo + ", description=" + description
            + ", status=" + status + ", dateCreated=" + dateCreated
            + ", dateUpdated=" + dateUpdated + "]";
}
}

我收到的消息是: 方法失败:HTTP/1.1 400 错误请求 发生 JAXBException:类
javax.jdo.identity.LongIdentity 或其任何父类(super class)在此上下文中都是已知的。 javax.jdo.identity.LongIdentity 类及其任何父类(super class)对此都是已知的 上下文..

我是 xml 注释新手。 请指教......

谢谢

最佳答案

一些 JPA 实现操作实体类的字节码。这可能涉及添加字段。由于您在 JAXB 映射中使用字段访问,因此您可能会受到此影响。我建议改用 PROPERTY 访问,并将注释移至 get 方法。

了解更多信息

关于xml - JAXBException 发生 : class javax. jdo.identity.LongIdentity 及其任何父类(super class)在此上下文中均未知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13299734/

相关文章:

java - 如何解决 java.lang.NoClassDefFoundError : javax/xml/bind/JAXBException

java - XML 到 JAXB 的绑定(bind)是否具有嵌套元素?

c# - 使用 XmlDocument 从带有或不带有命名空间的 xml 文件中读取

java - 哪些 xml/xslt 库目前适用于 java?

java - MultipartEntityBuilder 将 Content-Disposition header 添加到二进制文件并破坏它

jaxb - JAXB 有多灵活?

java - Android开发中类与xml布局的通信

.net - 在 .NET 中快速搜索 XMl 文件(或如何索引 XML 文件)

json - org.codehaus.jackson.map.JsonMappingException : Can not instantiate value of type [simple type, 类 models.Job] 来自 JSON 字符串

php - 通过 token / key 进行用户和 API 身份验证