gpt4 book ai didi

web-services - 没有无限循环的 JAX WS 服务上的 Jpa 实体

转载 作者:行者123 更新时间:2023-12-04 21:25:17 25 4
gpt4 key购买 nike

如何在不获取 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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com