0

How to overcome this error please?

@XmlRootElement(name="schema")
@Entity
public class SchemaBase implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id_schema;  
private String name_schema;
private String description_schema;
private String measuresCaption_schema;
private String defaultRole_schema;


@OneToMany (mappedBy="schema",cascade={CascadeType.MERGE,CascadeType.PERSIST})
private List<CubeBase> cubes;




 @XmlElementWrapper(name = "cube")  
   @XmlElement(name = "cube")
public List<CubeBase> getCubes() {
    return cubes;
}

public void setCubes(List<CubeBase> cubes) {
    this.cubes = cubes;
}



public int getId_schema() {
    return id_schema;
}
public void setId_schema(int id_schema) {
    this.id_schema = id_schema;
}
public String getName_schema() {
    return name_schema;
}
@XmlAttribute(name="name")
public void setName_schema(String name_schema) {
    this.name_schema = name_schema;
}
public String getDescription_schema() {
    return description_schema;
}
@XmlAttribute(name="description")
public void setDescription_schema(String description_schema) {
    this.description_schema = description_schema;
}
public String getMeasuresCaption_schema() {
    return measuresCaption_schema;
}
@XmlAttribute(name="measuresCaption")
public void setMeasuresCaption_schema(String measuresCaption_schema) {
    this.measuresCaption_schema = measuresCaption_schema;
}
public String getDefaultRole_schema() {
    return defaultRole_schema;
}
@XmlAttribute(name="defaultRole")
public void setDefaultRole_schema(String defaultRole_schema) {
    this.defaultRole_schema = defaultRole_schema;
}     
public void addCubeToShema(List<CubeBase> cubes){
   for(CubeBase cubeBase:cubes)
       cubeBase.setSchema(this);
   this.cubes=cubes;
}

}

and the other class is like this:

@XmlRootElement(namespace ="esprit.olap.domain.SchemaBase")
@Entity
public class CubeBase implements Serializable{

/**
 * Private Attribute 
 */
private static final long serialVersionUID = 1L;




@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id_cube;
private String name_cube;
private String description_cube;
private String caption_cube;
private boolean visible;
private boolean cache;
private boolean enabled;

@ManyToOne
private SchemaBase schema;


public boolean isCache() {
    return cache;
}

public void setCache(boolean cache) {
    this.cache = cache;
}
public boolean isEnabled() {
    return enabled;
}

public void setEnabled(boolean enabled) {
    this.enabled = enabled;
}
public boolean isVisible() {
    return visible;
}

public void setVisible(boolean visible) {
    this.visible = visible;
}   

public SchemaBase getSchema() {
    return schema;
}

public void setSchema(SchemaBase schema) {
    this.schema = schema;
}
public int getId_cube() {
    return id_cube;
}

public void setId_cube(int id_cube) {
    this.id_cube = id_cube;
}
public String getName_cube() {
    return name_cube;
}

public void setName_cube(String name_cube) {
    this.name_cube = name_cube;
}
public String getDescription_cube() {
    return description_cube;
}

public void setDescription_cube(String description_cube) {
    this.description_cube = description_cube;
}
public String getCaption_cube() {
    return caption_cube;
}

public void setCaption_cube(String caption_cube) {
    this.caption_cube = caption_cube;
}

}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • this is the error :[com.sun.istack.internal.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: esprit.olap.domain.SchemaBase@1c57009 -> esprit.olap.domain.CubeBase@eeca3a -> esprit.olap.domain.SchemaBase@1c57009] –  May 29 '14 at 00:11

2 Answers2

0

This appears to be a duplicate of JAXB A cycle is detected in the object graph and JAXB Mapping cyclic references to XML

(Normal Java serialization has logic to handle that case. I'm surprised that JAXB doesn't; it isn't that hard to do. Then again, I'm surprised JAXB has become as popular as it is.)

Community
  • 1
  • 1
keshlam
  • 7,931
  • 2
  • 19
  • 33
0

Add annotation @XmlTransient before setting Lists , In this exemple you have to add @XmlTransient before addCubeToShema method.