Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在对象图中检测到循环。这将导致无限深的XML_Java_Hibernate_Jaxb - Fatal编程技术网

Java 在对象图中检测到循环。这将导致无限深的XML

Java 在对象图中检测到循环。这将导致无限深的XML,java,hibernate,jaxb,Java,Hibernate,Jaxb,我有两个DTO对象,比如A和B,它们有getter和setter,用于从数据库中获取数据。问题是当我调用A时,B被调用,B再次指向A,并创建了一个循环 我不能忽略/隐藏创建循环的方法。我需要取A和B的全部数据 有什么办法可以实现吗 请帮忙 这是导致问题的代码。这是调用环境DTO的应用程序DTO @OneToMany(mappedBy="application", fetch=FetchType.LAZY ,cascade=CascadeType.ALL ) pub

我有两个DTO对象,比如A和B,它们有getter和setter,用于从数据库中获取数据。问题是当我调用A时,B被调用,B再次指向A,并创建了一个循环

我不能忽略/隐藏创建循环的方法。我需要取A和B的全部数据

有什么办法可以实现吗

请帮忙

这是导致问题的代码。这是调用环境DTO的应用程序DTO

@OneToMany(mappedBy="application", fetch=FetchType.LAZY
        ,cascade=CascadeType.ALL
        )
public Set<EnvironmentDTO> getEnvironment() {
    return environment;
}

public void setEnvironment(Set<EnvironmentDTO> environment) {
    this.environment = environment;
}
在这里,循环正在被创建

@GET
@Path("/get")
@Produces({MediaType.APPLICATION_XML})
public List<ApplicationDTO> getAllApplications(){
    List<ApplicationDTO> allApplication = applicationService.getAllApplication();
    return allApplication;
}
这是我的rest调用,它将以XML格式给出结果,我认为在创建XML时,循环正在创建

@GET
@Path("/get")
@Produces({MediaType.APPLICATION_XML})
public List<ApplicationDTO> getAllApplications(){
    List<ApplicationDTO> allApplication = applicationService.getAllApplication();
    return allApplication;
}
@GET
@路径(“/get”)
@产生({MediaType.APPLICATION_XML})
公共列表getAllApplications(){
List allApplication=applicationService.getAllApplication();
返回所有应用程序;
}
这是应用程序DTO类

@Entity
@Table(name="application")
@org.hibernate.annotations.GenericGenerator(
name ="test-increment-strategy",strategy = "increment")

@XmlRootElement
public class ApplicationDTO implements Serializable {

@XmlAttribute
public Long appTypeId;

private static final long serialVersionUID = -8027722210927935073L;

private Long applicationId;

private String applicationName;

private ApplicationTypeDTO applicationType;

private String applicationDescription;

private Integer owner;

private Integer createdBy;

private Integer assignedTo;

private Date createTime;

private Date modifiedTime;

private Set<EnvironmentDTO> environment;

@Id
@GeneratedValue(generator = "test-increment-strategy")
@Column(name = "applicationId")
public Long getApplicationId() {
    return applicationId;
}

private void setApplicationId(Long applicationId) {
    this.applicationId = applicationId;
}

@Column(name = "applicationName")
public String getApplicationName() {
    return applicationName;
}

public void setApplicationName(String applicationName) {
    this.applicationName = applicationName;
}

@ManyToOne(targetEntity=ApplicationTypeDTO.class 
        ,fetch = FetchType.LAZY
        )
@JoinColumn(name="applicationType")

public ApplicationTypeDTO getApplicationType() {
    return applicationType;
}

public void setApplicationType(ApplicationTypeDTO applicationType) {
    this.applicationType = applicationType;
}

@Column(name = "description")
public String getApplicationDescription() {
    return applicationDescription;
}

public void setApplicationDescription(String applicationDescription) {
    this.applicationDescription = applicationDescription;
}

@Column(name = "owner")
public Integer getOwner() {
    return owner;
}

public void setOwner(Integer owner) {
    this.owner = owner;
}

@Column(name = "createdBy")
public Integer getCreatedBy() {
    return createdBy;
}

public void setCreatedBy(Integer createdBy) {
    this.createdBy = createdBy;
}

@Column(name = "assignedTo")
public Integer getAssignedTo() {
    return assignedTo;
}

public void setAssignedTo(Integer assignedTo) {
    this.assignedTo = assignedTo;
}

@Column(name = "createTime")
public Date getCreateTime() {
    return createTime;
}

public void setCreateTime(Date createTime) {
    this.createTime = createTime;
}

@Column(name = "modifiedTime")
public Date getModifiedTime() {
    return modifiedTime;
}

public void setModifiedTime(Date modifiedTime) {
    this.modifiedTime = modifiedTime;
}

@OneToMany(mappedBy="application", fetch=FetchType.LAZY
        ,cascade=CascadeType.ALL
        )
public Set<EnvironmentDTO> getEnvironment() {
    return environment;
}

public void setEnvironment(Set<EnvironmentDTO> environment) {
    this.environment = environment;
}
@Entity
@Table(name="environment")

@org.hibernate.annotations.GenericGenerator(
name = "test-increment-strategy",
strategy = "increment")
@XmlRootElement
public class EnvironmentDTO implements Serializable {

@XmlAttribute
public Long envTypeId;

@XmlAttribute
public Long appId;

private static final long serialVersionUID = -2756426996796369998L;

private Long environmentId;

private String environmentName;

private EnvironmentTypeDTO environmentType;

private Integer owner;

private Date createTime;

private Set<InstanceDTO> instances;

private ApplicationDTO application;

@Id
@GeneratedValue(generator = "test-increment-strategy")
@Column(name = "envId")
public Long getEnvironmentId() {
    return environmentId;
}

private void setEnvironmentId(Long environmentId) {
    this.environmentId = environmentId;
}

@Column(name = "envName")
public String getEnvironmentName() {
    return environmentName;
}

public void setEnvironmentName(String environmentName) {
    this.environmentName = environmentName;
}

@ManyToOne(targetEntity=EnvironmentTypeDTO.class)
@JoinColumn(name = "envType")
public EnvironmentTypeDTO getEnvironmentType() {
    return environmentType;
}

public void setEnvironmentType(EnvironmentTypeDTO environmentType) {
    this.environmentType = environmentType;
}

@Column(name = "owner")
public Integer getOwner() {
    return owner;
}

public void setOwner(Integer owner) {
    this.owner = owner;
}

@Temporal(TemporalType.DATE)
@Column(name = "createTime")
public Date getCreateTime() 
{
    return createTime;
}

public void setCreateTime(Date createTime) {
    this.createTime = createTime;
}

@OneToMany(mappedBy="environment", cascade=CascadeType.ALL, fetch = FetchType.EAGER)
public Set<InstanceDTO> getInstances() {
    return instances;
}

public void setInstances(Set<InstanceDTO> instances) {
    this.instances = instances;
}

@ManyToOne(targetEntity=ApplicationDTO.class )
@JoinColumn(name="fk_application_Id")
//@XmlTransient 
public ApplicationDTO getApplication() {
    return application;
}

public void setApplication(ApplicationDTO application) {
    this.application = application;
}
@实体
@表(name=“应用”)
@org.hibernate.annotations.GenericGenerator(
name=“测试增量策略”,strategy=“增量”)
@XmlRootElement
公共类ApplicationTo实现可序列化{
@XmlAttribute
公共长appTypeId;
私有静态最终长serialVersionUID=-8027722210927935073L;
私有长应用ID;
私有字符串applicationName;
私有应用程序类型到应用程序类型;
私有字符串applicationDescription;
私有整数所有者;
创建的私有整数;
分配给的私有整数;
私人日期和时间;
私人日期修改时间;
私人环境;
@身份证
@GeneratedValue(generator=“测试增量策略”)
@列(name=“applicationId”)
公共长getApplicationId(){
返回应用程序ID;
}
私有void setApplicationId(长applicationId){
this.applicationId=applicationId;
}
@列(name=“applicationName”)
公共字符串getApplicationName(){
返回applicationName;
}
public void setApplicationName(字符串applicationName){
this.applicationName=applicationName;
}
@manytone(targetEntity=ApplicationTypeDTO.class
,fetch=FetchType.LAZY
)
@JoinColumn(name=“applicationType”)
公共应用程序类型到getApplicationType(){
返回应用程序类型;
}
public void setApplicationType(ApplicationTypeDTO applicationType){
this.applicationType=applicationType;
}
@列(name=“description”)
公共字符串getApplicationDescription(){
返回应用程序描述;
}
public void setApplicationDescription(字符串applicationDescription){
this.applicationDescription=applicationDescription;
}
@列(name=“owner”)
公共整数getOwner(){
归还所有人;
}
公共void集合所有者(整数所有者){
this.owner=所有者;
}
@列(name=“createdBy”)
公共整数getCreatedBy(){
返回createdBy;
}
公共void setCreatedBy(整数createdBy){
this.createdBy=createdBy;
}
@列(name=“assignedTo”)
公共整数getAssignedTo(){
分配给的回报;
}
public void setAssignedTo(整数assignedTo){
this.assignedTo=assignedTo;
}
@列(name=“createTime”)
公共日期getCreateTime(){
返回创建时间;
}
public void setCreateTime(日期createTime){
this.createTime=createTime;
}
@列(name=“modifiedTime”)
公共日期getModifiedTime(){
返回修改时间;
}
公共作废设置修改时间(日期修改时间){
this.modifiedTime=modifiedTime;
}
@OneToMany(mappedBy=“application”,fetch=FetchType.LAZY
,cascade=CascadeType.ALL
)
公共集getEnvironment(){
回归环境;
}
公共空间集合环境(集合环境){
这个。环境=环境;
}
这是环境DTO类

@Entity
@Table(name="application")
@org.hibernate.annotations.GenericGenerator(
name ="test-increment-strategy",strategy = "increment")

@XmlRootElement
public class ApplicationDTO implements Serializable {

@XmlAttribute
public Long appTypeId;

private static final long serialVersionUID = -8027722210927935073L;

private Long applicationId;

private String applicationName;

private ApplicationTypeDTO applicationType;

private String applicationDescription;

private Integer owner;

private Integer createdBy;

private Integer assignedTo;

private Date createTime;

private Date modifiedTime;

private Set<EnvironmentDTO> environment;

@Id
@GeneratedValue(generator = "test-increment-strategy")
@Column(name = "applicationId")
public Long getApplicationId() {
    return applicationId;
}

private void setApplicationId(Long applicationId) {
    this.applicationId = applicationId;
}

@Column(name = "applicationName")
public String getApplicationName() {
    return applicationName;
}

public void setApplicationName(String applicationName) {
    this.applicationName = applicationName;
}

@ManyToOne(targetEntity=ApplicationTypeDTO.class 
        ,fetch = FetchType.LAZY
        )
@JoinColumn(name="applicationType")

public ApplicationTypeDTO getApplicationType() {
    return applicationType;
}

public void setApplicationType(ApplicationTypeDTO applicationType) {
    this.applicationType = applicationType;
}

@Column(name = "description")
public String getApplicationDescription() {
    return applicationDescription;
}

public void setApplicationDescription(String applicationDescription) {
    this.applicationDescription = applicationDescription;
}

@Column(name = "owner")
public Integer getOwner() {
    return owner;
}

public void setOwner(Integer owner) {
    this.owner = owner;
}

@Column(name = "createdBy")
public Integer getCreatedBy() {
    return createdBy;
}

public void setCreatedBy(Integer createdBy) {
    this.createdBy = createdBy;
}

@Column(name = "assignedTo")
public Integer getAssignedTo() {
    return assignedTo;
}

public void setAssignedTo(Integer assignedTo) {
    this.assignedTo = assignedTo;
}

@Column(name = "createTime")
public Date getCreateTime() {
    return createTime;
}

public void setCreateTime(Date createTime) {
    this.createTime = createTime;
}

@Column(name = "modifiedTime")
public Date getModifiedTime() {
    return modifiedTime;
}

public void setModifiedTime(Date modifiedTime) {
    this.modifiedTime = modifiedTime;
}

@OneToMany(mappedBy="application", fetch=FetchType.LAZY
        ,cascade=CascadeType.ALL
        )
public Set<EnvironmentDTO> getEnvironment() {
    return environment;
}

public void setEnvironment(Set<EnvironmentDTO> environment) {
    this.environment = environment;
}
@Entity
@Table(name="environment")

@org.hibernate.annotations.GenericGenerator(
name = "test-increment-strategy",
strategy = "increment")
@XmlRootElement
public class EnvironmentDTO implements Serializable {

@XmlAttribute
public Long envTypeId;

@XmlAttribute
public Long appId;

private static final long serialVersionUID = -2756426996796369998L;

private Long environmentId;

private String environmentName;

private EnvironmentTypeDTO environmentType;

private Integer owner;

private Date createTime;

private Set<InstanceDTO> instances;

private ApplicationDTO application;

@Id
@GeneratedValue(generator = "test-increment-strategy")
@Column(name = "envId")
public Long getEnvironmentId() {
    return environmentId;
}

private void setEnvironmentId(Long environmentId) {
    this.environmentId = environmentId;
}

@Column(name = "envName")
public String getEnvironmentName() {
    return environmentName;
}

public void setEnvironmentName(String environmentName) {
    this.environmentName = environmentName;
}

@ManyToOne(targetEntity=EnvironmentTypeDTO.class)
@JoinColumn(name = "envType")
public EnvironmentTypeDTO getEnvironmentType() {
    return environmentType;
}

public void setEnvironmentType(EnvironmentTypeDTO environmentType) {
    this.environmentType = environmentType;
}

@Column(name = "owner")
public Integer getOwner() {
    return owner;
}

public void setOwner(Integer owner) {
    this.owner = owner;
}

@Temporal(TemporalType.DATE)
@Column(name = "createTime")
public Date getCreateTime() 
{
    return createTime;
}

public void setCreateTime(Date createTime) {
    this.createTime = createTime;
}

@OneToMany(mappedBy="environment", cascade=CascadeType.ALL, fetch = FetchType.EAGER)
public Set<InstanceDTO> getInstances() {
    return instances;
}

public void setInstances(Set<InstanceDTO> instances) {
    this.instances = instances;
}

@ManyToOne(targetEntity=ApplicationDTO.class )
@JoinColumn(name="fk_application_Id")
//@XmlTransient 
public ApplicationDTO getApplication() {
    return application;
}

public void setApplication(ApplicationDTO application) {
    this.application = application;
}
@实体
@表(name=“环境”)
@org.hibernate.annotations.GenericGenerator(
name=“测试增量策略”,
策略=“增量”)
@XmlRootElement
实现可序列化的公共类环境{
@XmlAttribute
公共长envTypeId;
@XmlAttribute
公共长appId;
私有静态最终长serialVersionUID=-27564269969796369998L;
私人长环境ID;
私有字符串环境名称;
私有环境类型到环境类型;
私有整数所有者;
私人日期和时间;
私有集实例;
私人申请对申请;
@身份证
@GeneratedValue(generator=“测试增量策略”)
@列(name=“envId”)
公共长getEnvironmentId(){
返回环境ID;
}
私有void setEnvironmentId(长environmentId){
this.environmentId=environmentId;
}
@列(name=“envName”)
公共字符串getEnvironmentName(){
返回环境名称;
}
public void setEnvironmentName(字符串environmentName){
this.environmentName=环境名称;
}
@manytone(targetEntity=EnvironmentTypeDTO.class)
@JoinColumn(name=“envType”)
public EnvironmentTypeDTO getEnvironmentType(){
返回环境类型;
}
public void setEnvironmentType(EnvironmentTypeDTO environmentType){
this.environmentType=environmentType;
}
@列(name=“owner”)
公共整数getOwner(){
归还所有人;
}
公共void集合所有者(整数所有者){
this.owner=所有者;
}
@时态(TemporalType.DATE)
@列(name=“createTime”)
公共日期getCreateTime()
{
返回创建时间;
}
public void setCreateTime(日期createTime){
this.createTime=createTime;
}
@OneToMany(mappedBy=“environment”,cascade=CascadeType.ALL,fetch=FetchType.EAGER)
公共集getInstances(){
返回实例;
}
公共void集合实例(集合实例){
this.instances=实例;
}
@多通(targetEntity=applicationTo.class)
@JoinColumn(name=“fk\U应用程序\U Id”)
//@XmlTransient
公共应用程序到getApplication(){
退货申请;
}
公共应用程序(ApplicationTo应用程序){
这个应用程序=应用程序;
}

您的对象图是循环的。这并没有本质上的错误,这是使用JPA的自然结果

问题不在于对象图是循环的,而在于
import javax.persistence.*;

@Entity
public class Customer {

    @Id
    private long id;

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

}
public class CustomerModel{
    private long id;
    //you can call different WS to get the Address class, or combine to this model

    public void setFromJpa(Customer customer){
        this.id = customer.id;
    }
}