gpt4 book ai didi

java - JAXB:在对象图中检测到循环

转载 作者:行者123 更新时间:2023-12-02 12:18:40 24 4
gpt4 key购买 nike

我有两个实体。类别实体:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name = "EPBS_DATA.NEWS_CATEGORY")
@XmlType(propOrder = { "id", "name", "news" })
public class CategoryEntity {
public final static String ID_GENERATOR_NAME =
"EPBS_DATA.sq_news_category";
@Id
@Column(name = "ID", nullable = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = ID_GENERATOR_NAME)
@SequenceGenerator(name = ID_GENERATOR_NAME,
sequenceName = ID_GENERATOR_NAME, allocationSize = 1)
private long id;

@Column(name = "CATEGORY_NAME", nullable = false, length = 1024)
private String name;
@ManyToMany(mappedBy = "categories")
@XmlElementWrapper(name = "news")
@XmlElement(name = "")
private List<NewsEntity> news = new ArrayList<NewsEntity>();

setters/getters
}

和NewsEntity

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name = "EPBS_DATA.NEWS")
@XmlType(propOrder =
{ "id", "body", "lead", "creatorId", "date", "federal", "regId",
"raw", "file", "title", "editDate", "fixed", "categories",
"publishDates" })
public class NewsEntity {
public final static String ID_GENERATOR_NAME = "EPBS_DATA.SQ_EPBS";
public final static String GET_NEWS_BY_DATE = "NewsEntity.getNewsByDate";
public final static String GET_NEWS_COUNT = "NewsEntity.getNewsCount";
public final static String GET_DATES = "NewsEntity.getDates";
@Id
@Column(name = "NEWS_ID", nullable = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = ID_GENERATOR_NAME)
@SequenceGenerator(name = ID_GENERATOR_NAME,
sequenceName = ID_GENERATOR_NAME, allocationSize = 1)
private long id;
@Column(name = "NEWS_BODY", nullable = true)
@Lob
private String body;
@ManyToMany
@JoinTable(name = "EPBS_DATA.NEWS_CATEGORY_ASSIGMENT",
joinColumns = @JoinColumn(name = "ID_NEWS",
referencedColumnName = "NEWS_ID"),
inverseJoinColumns =
@JoinColumn(name = "ID_CATEGORY", referencedColumnName = "ID"))
@XmlInverseReference(mappedBy = "news")
@XmlElementWrapper(name = "categories")
@XmlElement(name = "")
private List<CategoryEntity> categories = new ArrayList<CategoryEntity>();

我有错误 在对象图中检测到循环。这将导致无限深的 XML: jpa.news.CategoryEntity@79c7b9d3 -> jpa.news.NewsEntity@31453ead -> jpa.news.CategoryEntity@79c7b9d3]

我尝试使用@XmlTransient和@XmlInverseReference,但无论我有什么错误。

最佳答案

您的 beans 相互引用:CategoryEntity.news 至少包含一个 NewsEntity,其属性类别包含前述的 CategroyEntity。尝试将其输出为 XML 会导致无限循环。根据您的“主导”实体,您必须将类别或新闻标记为 @XmlTransient。

关于java - JAXB:在对象图中检测到循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45964033/

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