users@jaxb.java.net

Re: A cycle in object graph detected in JPA.

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Sun, 25 Apr 2010 16:44:03 +0200

Hi,


> I am trying to figure out this error since 5 hours without any success. SO i
> finally thought of posting in here. Please help i am really in big trouble.
> I am stuck on this and see no way of solving this error. This is my database
> structure
>
>
>
>    tblBlogRegion
>
>    BlogRegionId (primary key)
>    BlogRegionName
>
>
>    tblGadget
>
>    GadgetId(primary key)
>    GadgetName
>
>    tblBlogs
>
>    BlogId(primary key)
>    Blogname
>    BlogTypeId (reference key from tblSiteTerm
>
>
>    tblSiteTerms
>
>    SiteTermsId(primary key)
>    SiteTermsName
>
>
>    tblBlogGadgets
>
>    BlogGadgetsId(primary key)
>    BlogRegionId(foreign key from tblBlogRegion)
>    BlogId(foreign key from tblBlog)
>    GadgetId(foreign key from tblGadget)
>
> Is it not normal database structure? Do you see anything that is cyclic?
> WHen i try to fetch list from tblGadgets i get this error :-
>
>    [com.sun.istack.SAXException2: A cycle is detected in the object graph.
> This will cause infinitely deep XML: entity.BlogGadgets[blogGadgetsId=1] ->
> entity.Blogs[blogId=2] -> entity.BlogGadgets[blogGadgetsId=1]]
>
>
> I am trying to get list from web service. The entities are autogenerated by
> Netbeans and i haven't touched it. What can i do to overcome this problem?

Well, you obviously have BlogGadget->Blog->BlogGadget cycle as you're
probably modelling the m:m relationship. Either remove the association
on one end or use @XmlID/_at_XmlIDREF annotations to break the cycle.

Bye.
/lexi