Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Direct self-reference leading to cycle error despite having JsonManagedReference and JsonBackReferen
Direct self-reference leading to cycle error despite having JsonManagedReference and JsonBackReferen [message #1714873] Tue, 17 November 2015 11:59
Ponic Pan is currently offline Ponic PanFriend
Messages: 3
Registered: January 2015
Junior Member
I am getting the following error despite I have JsonManagedReference and JsonBackReference in entity classes

org.codehaus.jackson.map.JsonMappingException: Direct self-reference leading to cycle (through reference chain: java.util.Vector[0]->org.eclipse.persistence.internal.jpa.querydef.TupleImpl["elements"]->java.util.ArrayList[0]->org.eclipse.persistence.internal.jpa.querydef.PathImpl["currentNode"]->org.eclipse.persistence.internal.expressions.QueryKeyExpression["baseExpression"]->org.eclipse.persistence.expressions.ExpressionBuilder["builder"])


What could be the reason for this and how can I get rid of this?

Entity classes code snippets

@Entity
@Table(name = "PRODUCT_CATALOGUES")
@IdClass(ProductCataloguePK.class)
public class ProductCatalogue implements Serializable {

    @Id
    @Column(name="PROD_ID", nullable = false, insertable = false, 
        updatable = false)
    private String prodId;

    @Id
    @Column(name="USER_ID")
    private String userId;

    @JsonManagedReference("prod")
    @ManyToOne
    @JoinColumn(name = "PROD_ID", referencedColumnName = "PROD_ID")
    private ProductList productList;

    @JsonIgnore
    public ProductList getProductList() {
        return productList;
    }    

    ......
    ......
    ......


@Entity
@Table(name = "PRODUCT_LISTS")
    public class ProductList implements Serializable {

    @Id
    @Column(name = "PROD_ID", nullable = false)
    private String prodId;

    @Column(name="PROD_DESC")
    private String prodDesc;

    @JsonBackReference("prod")
    @OneToMany(mappedBy = "productList")
    private List<ProductCatalogue> productCatalogueList;

    @JsonIgnore
    public List<ProductCatalogue> getProductCatalogueList() {
        return productCatalogueList;
    }

    ......
    ......
    ......


Criteria API code snippet

CriteriaQuery<Tuple> cq = cb.createTupleQuery();

Root<ProductCatalogue> pc = cq.from(ProductCatalogue.class);
Root<ProductList> al = cq.from(ProductList.class);

Expression<String> ct = 
cb.concat(cb.concat(pc.get(ProductCatalogue_.prodId), " # "), 
                                   pc.get(ProductCatalogue_.userId));

cq.multiselect(pc.get(ProductCatalogue_.userId), 
cb.selectCase().when(cb.equal(pc.get(ProductCatalogue_.prodId), 
"ZCX"), 
stringConcat).otherwise(pc.get(ProductCatalogue_.prodId)));

Join<ProductCatalogue, ProductList> joinPr =
pc.join(ProductCatalogue_.productList, JoinType.LEFT);


Detailed exception stack

org.codehaus.jackson.map.JsonMappingException: Direct self-reference leading to cycle (through reference chain: java.util.Vector[0]->org.eclipse.persistence.internal.jpa.querydef.TupleImpl["elements"]->java.util.ArrayList[0]->org.eclipse.persistence.internal.jpa.querydef.PathImpl["currentNode"]->org.eclipse.persistence.internal.expressions.QueryKeyExpression["baseExpression"]->org.eclipse.persistence.expressions.ExpressionBuilder["builder"]) at org.codehaus.jackson.map.ser.BeanPropertyWriter._reportSelfReference(BeanPropertyWriter.java:491) at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:429) at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150) at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112) at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446) at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150) at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112) at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446) at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150) at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112) at org.codehaus.jackson.map.ser.std.StdContainerSerializers$IndexedListSerializer.serializeContents(StdContainerSerializers.java:122) at org.codehaus.jackson.map.ser.std.StdContainerSerializers$IndexedListSerializer.serializeContents(StdContainerSerializers.java:71) at org.codehaus.jackson.map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86) at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446) at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150) at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112) at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:72) at org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:23) at org.codehaus.jackson.map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86) at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:659) at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:271) at org.codehaus.jackson.map.ObjectWriter.writeValue(ObjectWriter.java:325) at org.codehaus.jackson.jaxrs.JacksonJsonProvider.writeTo(JacksonJsonProvider.java:556) at com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.writeTo(JacksonProviderProxy.java:160) at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1479) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381) at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716) at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
Previous Topic:HELP! What are the possible types of value an @XmlPath can have?
Next Topic:EclipseLink Constraint Violation Issue
Goto Forum:
  


Current Time: Tue Mar 09 11:49:08 GMT 2021

Powered by FUDForum. Page generated in 0.01954 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top