客户端代码如下所示:
String urlGetRequestsByCustomer = baseUrl + "getRequestsByCustomer?customerID=";
byte[] getRequestsByCustomerResponse = customerAgent
.sendGetMethod(urlGetRequestsByCustomer + custNo);
Unmarshaller unmarshaller = customerAgent
.getUnmarshaller(ServiceRequests.class);
StringReader reader = new StringReader(new String(
getRequestsByCustomerResponse));
服务请求.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;
}
}
服务请求.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 或其任何超类在此上下文中是已知的.. 类 javax.jdo.identity.LongIdentity 或任何它的超类在这种情况下是已知的..
我是 xml 注释的新手。请指教 .....
谢谢