JAXB与JPA一起使用,抛出IllegalAnnotationsException

时间:2011-03-21 18:11:18

标签: jpa annotations jaxb

我已经在这个地方堆了好几天了。任何帮助将不胜感激。

这是我的故事: 我有一个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 wrapper

@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

1 个答案:

答案 0 :(得分:3)

你有一个大写'G'

@XmlElement(name = "HasMoreScreenShot")
public String GetHasMoreScreenShot() {
    return hasMoreScreenShot;
}