3

我有一个用于解组 xml 流的 JAXB/Entity 对象库。我可以毫无问题地作为 Java SE 应用程序运行。我已将所有内容转移到使用 Netbeans 6.9 和 Glassfish 3.01 的 Java EE 应用程序中。我现在遇到了一些异常,如下所示。

com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 19 counts of IllegalAnnotationExceptions
Property _persistence_productBase_vh is present but not specified in @XmlType.propOrder
        this problem is related to the following location:
                at protected org.eclipse.persistence.indirection.WeavedAttributeValueHolderInterface entitiesjaxb.cmic.ajrs.com.ProductSorts._persistence_productBase_vh
                at entitiesjaxb.cmic.ajrs.com.ProductSorts
                at public entitiesjaxb.cmic.ajrs.com.ProductSorts entitiesjaxb.cmic.ajrs.com.ObjectFactory.createProductSorts()
                at entitiesjaxb.cmic.ajrs.com.ObjectFactory

我的问题是我的enties/jaxb 文件中的任何地方都没有xml 元素或变量_persistence_productBase_vh。我假设这是由 Glassfish 和 EclipseLink 添加的。有谁知道有什么方法可以忽略这些属性?这是 xml 中的实体和示例。

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ProductSorts", propOrder = {
    "pkId",
    "productBase",
    "field",
    "value",
    "ts"
})

@Entity
@Table(name = "product_sorts")
@NamedQueries({
    //@NamedQuery(name = "ProductSorts.findAll", query = "SELECT p FROM ProductSorts p"),
    @NamedQuery(name = "ProductSorts.findByPkId", query = "SELECT p FROM ProductSorts p WHERE p.pkId = :pkId"),
    @NamedQuery(name = "ProductSorts.findByField", query = "SELECT p FROM ProductSorts p WHERE p.field = :field"),
    @NamedQuery(name = "ProductSorts.findByValue", query = "SELECT p FROM ProductSorts p WHERE p.value = :value"),
    @NamedQuery(name = "ProductSorts.findByTs", query = "SELECT p FROM ProductSorts p WHERE p.ts = :ts")})
public class ProductSorts implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "pk_id")
    private Integer pkId;
    @Column(name = "field")
    @XmlElement(name = "Field")
    private String field;
    @Column(name = "value")
    @XmlElement(name = "Value")
    private String value;
    @Basic(optional = false)
    @Column(name = "ts")
    @Temporal(TemporalType.TIMESTAMP)
    @XmlElement(required = true)
    @XmlSchemaType(name = "dateTime")
    private Date ts;
    @JoinColumn(name = "pk_product", referencedColumnName = "pk_id")
    @ManyToOne(fetch = FetchType.LAZY)
    private ProductBase productBase;

    public ProductSorts() {
    }

    public ProductSorts(Integer pkId) {
        this.pkId = pkId;
    }



<ProductSorts>
  <pkID>317926</pkID>
  <pkProduct>118647</pkProduct>
  <Field>3D TECHNOLOGY</Field>
  <Value>No</Value>
  <ts>1970-01-13T00:43:15.947</ts>
</ProductSorts>
4

1 回答 1

1

此属性 (_persistence_productBase_vh) 已编织到 JPA 实体中。您可以在 JAXB 映射中使用属性访问来解决此问题。

@XmlAccessorType(XmlAccessType.PROPERTY)

当 EclipseLink 进行字节码编织时,它会检查类路径上的 JAXB。如果存在 JAXB,它将使用 @XmlTransient 注释编织该属性。您使用的是静态编织还是动态编织?如果您使用静态编织,则需要确保 JAXB API jar 在您的类路径中。

于 2011-04-18T17:21:47.323 回答