users@glassfish.java.net

Re: Circular Reference when using Stateless Session Beans as WebService

From: Sahoo <Sahoo_at_Sun.COM>
Date: Tue, 23 Oct 2007 08:56:23 +0530

Since yours is a readonly method, you can easily work around this by problem by simply detaching the objects before returning from the function:
*em.clear();* // detach all the entities, so updates won't go to database
return list;


Thanks,
Sahoo

glassfish_at_javadesktop.org wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>