如何通过JAX WS Web服务发送JPA生成的实体,而又没有获得
XML无限循环异常是因为这些实体中的引用循环?

任何想法?我发现这种MOXy可以...部分地做到这一点。但是我已经生成了实体,并手动向每个实体添加XmlTransient和此类注释,这很疯狂。

您还有其他想法怎么做吗?

谢谢!

最佳答案

EclipseLink JAXB (MOXy)可以使用@XmlInverseReference进行双向映射来处理此问题:

import javax.persistence.*;

@Entity
public class Customer {

    @Id
    private long id;

    @OneToOne(mappedBy="customer", cascade={CascadeType.ALL})
    private Address address;

}


import javax.persistence.*;
import org.eclipse.persistence.oxm.annotations.*;

@Entity
public class Address implements Serializable {

    @Id
    private long id;

    @OneToOne
    @JoinColumn(name="ID")
    @MapsId
    @XmlInverseReference(mappedBy="address")
    private Customer customer;

}

有关更多信息,请参见:
  • http://bdoughan.blogspot.com/2010/07/jpa-entities-to-xml-bidirectional.html
  • http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JPA

  • 您也可以为此使用MOXy的元数据外部化表示形式。有关更多信息,请参见:
  • XML to Java mapping tool - with mapping descriptor
  • http://wiki.eclipse.org/EclipseLink/Examples/MOXy/EclipseLink-OXM.XML
  • 关于web-services - 通过JAX WS服务的Jpa实体,没有无限循环,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4376597/

    10-12 05:21