好吧,我一直在嘗試這一天的結束,但似乎無法找到什麼是錯的。 這裏的基本思想是,我試圖創建一個寧靜的Web服務,它將顯示兩個實體bean之間具有多重雙向關係的 的屬性。現在我想使用JAXB的moxy實現 來利用@XmlInverseReference註釋來維護引用完整性,但不斷提出異常。下面是一個除了從我的類 我使用的glassfish 3.1.1和MOXY的EclipseLink 2.3.0錯誤編組與moxy註釋類錯誤
Passenger Class:
package kharesoft.sita;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.persistence.*;
import javax.xml.bind.annotation.*;
@XmlRootElement
@XmlType(propOrder = {"id", "firstName", "lastName", "boardingNo", "seatNo", "flightNo", "dateOfFlight", "bags"})
@Entity
@NamedQuery(name = "findPaxByBagTag", query = "select p from Passenger p,IN (p.bags) b where b.bagTagNo=:bagTagNo")
@XmlAccessorType(XmlAccessType.FIELD)
public class Passenger implements Serializable {
@XmlElement
private String firstName;
@XmlElement
private String lastName;
@XmlElement
private String boardingNo;
@XmlElement
private String seatNo;
@XmlElement
private String flightNo;
@XmlElement
@Temporal(javax.persistence.TemporalType.DATE)
private Date dateOfFlight;
@XmlElementWrapper
@XmlElements({
@XmlElement(name = "bagtag")})
@OneToMany(mappedBy = "passenger")
private Set<Bag> bags;
private static final long serialVersionUID = 1L;
@XmlElement
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Set<Bag> getBags() {
return bags;
}
public void setBags(Set<Bag> bags) {
this.bags = bags;
}
//Remaining getters and setters not shown
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Passenger)) {
return false;
}
Passenger other = (Passenger) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "kharesoft.sita.Passenger[ id=" + id + " ]";
}
}
Bag Class:
package kharesoft.sita;
import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.persistence.oxm.annotations.XmlInverseReference;
@XmlRootElement
@Entity
@NamedQuery(name = "findBagWithTagNo", query = "select b from Bag b where b.bagTagNo=:bagTagNo")
@XmlAccessorType(XmlAccessType.FIELD)
public class Bag implements Serializable {
private static final long serialVersionUID = 1L;
@XmlElement
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@XmlElement
private String bagTagNo;
@XmlElement
@ManyToOne
private Passenger passenger;
//other getters and setters not shown
@XmlInverseReference(mappedBy = "bags")
public Passenger getPassenger() {
return passenger;
}
public void setPassenger(Passenger passenger) {
this.passenger = passenger;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Bag)) {
return false;
}
Bag other = (Bag) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return bagTagNo;
}
}
例外:
嚴重:映射例外響應:500(內部服務器錯誤) 的javax。 ws.rs.WebApplicationException:javax.xml.bind.JAXBException: 異常說明:在類[kharesoft.sita.Bag]上找到名爲[passenger]的重複屬性 - 鏈接的異常: [異常[EclipseLink-50072](Eclipse持久性服務 - 2.3.0.v20110604-r9504):org.eclipse.persistence.exceptions.JAXBException 異常說明:在類[kharesoft.sita.Bag]上找到名爲[passenger]的重複屬性] at com.sun.jersey.core.provider.jaxb.AbstractListElementProvider.writeTo(AbstractListElementProvider.java:183) at com.sun .jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437) at com.sun.jersey.server .impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) at com.sun.jersey.spi.container .servlet.WebComponent.service(WebComponent.java:416) at com.sun.jersey.spi.container.servlet.ServletContainer。服務(ServletContainer.java:537) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) at org.apache.catalina.core。 StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98) at com.sun.enterprise.web.PESessi onLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162) 在org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174) at com.sun上的org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) 。 grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask。 java:1019) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain。的java:90) 在com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) 在com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) 在com.sun.grizzly。 SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:722) 引起:javax.xml.bind.JAXBException: 異常說明:重複屬性名爲[乘客]階級[kharesoft.sita.Bag] 發現 - 與聯EXCE ption: [異常[EclipseLink的-50072(Eclipse持久服務 - 2.3.0.v20110604-r9504):org.eclipse.persistence.exceptions.JAXBException 異常說明:重複屬性名爲[乘客]在類中找到[kharesoft.sita .Bag]] at org.eclipse.persistence.jaxb.JAXBContext $ TypeMappingInfoInput.createContextState(JAXBContext.java:825) at org.eclipse.persistence.jaxb.JAXBContext。(JAXBContext.java:136) at org.eclipse .persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:142) 在org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:129) 在org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory .java:93) at org.eclipse.persistence.jaxb.JAXBContextF actory.createContext(JAXBContextFactory.java:83) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本機方法) 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:43) at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:263) at javax.xml.bind.ContextFinder(java.lang.reflect.Method.invoke(Method.java:601) .newInstance(ContextFinder.java:250) at javax.xml.bind.ContextFinder.find(ContextFinder.java:400) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:652) at javax.xml .bind.JAXBContext.newInstance(JAXBContext.java:599) 在的com.sun。 jersey.core.provider.jaxb.AbstractJAXBProvider.getStoredJAXBContext(AbstractJAXBProvider.java:189) 在com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getJAXBContext(AbstractJAXBProvider.java:182) 在com.sun.jersey。 core.provider.jaxb.AbstractJAXBProvider.getMarshaller(AbstractJAXBProvider.java:160) at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getMarshaller(AbstractJAXBProvider.java:139) at com.sun.jersey.core。 (Eclipse持久性服務 - 2.3.0.v20110604-r9504):org.eclipse.persistence。 exceptions.JAXBException 異常說明:重複屬性名爲[乘客]階級[kharesoft.sita.Ba發現g] at org.eclipse.persistence.exceptions.JAXBException.duplicatePropertyName(JAXBException.java:943) at org.eclipse.persistence.jaxb.compiler.TypeInfo.addProperty(TypeInfo.java:265) at org.eclipse。 persistence.jaxb.compiler.TypeInfo.setProperties(TypeInfo.java:292) at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.buildTypeInfo(AnnotationsProcessor.java:677) at org.eclipse.persistence.jaxb.compiler。 AnnotationsProcessor.postBuildTypeInfo(AnnotationsProcessor.java:591) at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.buildNewTypeInfo(AnnotationsProcessor.java:4050) at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processPropertyTypes(AnnotationsProcessor。 java:858) at org.eclipse.persistence。在org.eclipse.persistence.jaxb.JAXBContext $ TypeMappingInfoInput.createContextState(Generator.java:147) (JAXBContext.java:822) ... 52更多
您的屏幕元素從視圖中隱藏。按Esc鍵或將指針移動到屏幕中心以返回到郵件。 按Esc或移動指針在這裏返回到Mail.by上由 WineSo清新干淨。 AllPhotoColor
謝謝杜漢。我已經這樣做了,但我得到了一個不受支持的屬性異常。 – kharesoft