users@glassfish.java.net

Circular Reference when using Stateless Session Beans as WebService

From: <glassfish_at_javadesktop.org>
Date: Mon, 22 Oct 2007 06:19:46 PDT

I have a bi-directional relationship and whenever i try findAll() from my Stateless session bean which is also a WebService I am getting this error

“com.sun.istack.SAXException2: A cycle is detected in the object graph. This
will cause infinitely deep XML:”

I have seen a few people posting this error and one of the solutions was to make
an object Reference null in the Session Bean in one direction.

This doesnt work for me as I am using Container Managed Persistence and I am setting object reference null in a managed entity. This is causing object reference to get updated as it tries to synchronize the Entiity Bean with datasbe.

Below is my Stateless Session :

@Stateless
@WebService

public class ValidAppStatusFacade implements ValidAppStatusFacadeLocal {

       @PersistenceContext
        private EntityManager em;

         /** Creates a new instance of ValidAppStatusFacade */
         public ValidAppStatusFacade() {
         }

         public List findAll() {

            List list = (List)em.createQuery("select object(o) from ValidAppStatus as o").getResultList();

            for(Iterator<ValidAppStatus> i = list.iterator(); i.hasNext(); ){
                    ValidAppStatus validApp = i.next();
                     for(Application application:validApp.getApplicationCollection()){
                              application.applicationStatus = null; //ERROR HERE AS IT UPDATES OBJECT
                      }
            }

            return list;
         }
}

Thanks for your help.
[Message sent by forum member 'ad1900' (ad1900)]

http://forums.java.net/jive/thread.jspa?messageID=241500