1
我已經在這個地方堆放了幾天。任何幫助將不勝感激。JAXB與JPA一起工作,拋出IllegalAnnotationsException
這是我的故事: 我有一個JPA實體類(ExtOffer),現在我使用JAXB註釋對它進行註釋以便由JAXB執行marshall/unmarshall。我還創建了一個包裝類(ExtOffers),它基本上是ExtOffer的集合。 當我調用JAXBContext.newInstance(ExtOffers.class)時,我得到一個IllegalAnnotationsException:JAXB註釋放置在不是JAXB屬性的方法上。
我搜索谷歌和一些職位說,這是由於註釋@XmlElement錯誤的地方。 但我的類有@XmlAccessorType(XmlAccessType.NONE)註釋,只有getter方法已用@Xmlelement註釋。
下面是我ExtOffer類和ExtOffers類:
// ExtOffer:
@Entity
@Table (name = "extoffer")
@XmlType(name = "ExtOfferType")
@XmlAccessorType(XmlAccessType.NONE)
public class ExtOffer {
public ExtOffer() {
}
@Id
@Column(name = "OfferID", nullable = false, unique = true, length = 32)
protected String offerId;
@Column(name = "HasMoreScreenShot", nullable = false, unique = false, length = 1)
private String hasMoreScreenShot;
public void setOfferId(String offerId) {
this.offerId = offerId;
}
@XmlElement(name="OfferID", required = true)
public String getOfferId() {
return offerId;
}
public void setHasMoreScreenShot(String hasMoreScreenShot) {
this.hasMoreScreenShot= hasMoreScreenShot;
}
@XmlElement(name = "HasMoreScreenShot")
public String GetHasMoreScreenShot() {
return hasMoreScreenShot;
}
}
// ExtOffers包裝器
@XmlRootElement(name="extoffers")
@XmlAccessorType(XmlAccessType.NONE)
public class ExtOfferWrapper {
private List<ExtOffer> extoffers;
public ExtOfferWrapper() {
}
@XmlElement(name="extoffer")
public List<ExtOffer> getExtoffers() {
return extoffers;
}
public void setExtoffers(List<ExtOffer> extoffers) {
this.extoffers = extoffers;
}
}
JAXB annotation is placed on a method that is not a JAXB property
this problem is related to the following location:
at @javax.xml.bind.annotation.XmlElement(nillable=false, name=HasMoreScreenShot, required=false, defaultValue=, type=class javax.xml.bind.annotation.XmlElement$DEFAULT, namespace=##default)
at com.symbio.fuhu.appstore.jpa.entity.ExtOffer
at public java.util.List com.symbio.fuhu.appstore.jaxb.mapping.wrapper.ExtOfferWrapper.getExtoffers()
at com.symbio.fuhu.appstore.jaxb.mapping.wrapper.ExtOfferWrapper
OMG。感謝您的幫助,並對打字錯誤感到抱歉.... \ r \ n和Blaise,我非常喜歡您的jaxb博客。它幫助我很多。再次感謝 – yzandrew 2011-03-21 18:20:30
@yzandrew - 沒問題,如果您希望在我的博客上看到任何JAXB主題,請通過我的聯繫頁面告訴我:http://bdoughan.blogspot.com/p/contact_01.html。另外,由於您是Stack Overflow的新手,因此慣例是將正確答案標記爲「已接受」。這讓其他用戶知道你已經找到了你需要的答案。 – 2011-03-21 18:27:31