You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nathan Schulte <na...@ngc.com> on 2009/07/30 21:35:32 UTC

Struts2 + JPA + JSON - Help with error

Hey all, I've got an issue I can't seem to solve.

I'm using Struts2 with the JSON Plugin.  The error I am receiving is below. 
This occurs when trying to access the Action.  I am not sure why this error is
being thrown, but I believe it has something to do with the way I implemented
the "Open Session in View" pattern.

The Action consists of querying via JPA for a List of entities, and returning
ActionSupport.SUCCESS.  The Action has a single result, <result name="success"
type="json"/>.  The entities that the list consists of have lazily fetched
associations.  My solution to the "Open Session in View" pattern is described
here, http://article.gmane.org/gmane.comp.jakarta.struts.user/170543, and works
for other result types (specifically the dispatcher type).

Here is a link to the error, http://pastebin.com/m5d0d22c8.

Thanks!



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts2 + JPA + JSON - Help with error

Posted by Martin Gainty <mg...@hotmail.com>.
disable lazy-initialisation in /WEB-INF/applicationContext.xml

<bean id="testDataProvider" class="org.apache.struts2.showcase.application.TestDataProvider" singleton="true" lazy-init="false"/>

Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> To: user@struts.apache.org
> From: nathan.schulte@ngc.com
> Subject: Re: Struts2 + JPA + JSON - Help with error
> Date: Fri, 31 Jul 2009 13:50:14 +0000
> 
> Nathan Schulte <nathan.schulte <at> ngc.com> writes:
> 
> > 
> > Nathan Schulte <nathan.schulte <at> ngc.com> writes:
> > > here, http://article.gmane.org/gmane.comp.jakarta.struts.user/170543,
> > http://article.gmane.org/gmane.comp.jakarta.struts.user/170543
> > 
> > > Here is a link to the error, http://pastebin.com/m5d0d22c8.
> > http://pastebin.com/m5d0d22c8
> > 
> > Also, here is the exception report (of a similar action) given as the HTTP
> > response:
> > http://pastebin.com/m21348ec5
> > 
> 
> I have found a fix for this issue.  As it turns out, because the JSON Plugin is
> using reflection, and the entities the JSON Plugin is reflecting on are using
> Hibernate/JPA "lazy initialization magic", the JSON Plugin was serializing the
> "magic" as well.  This "magic" contains references to underlying JPA
> implementation, which also contains references, which also contain references,
> all the way down past the JDBC layer.  I didn't go as far as to find out what
> was causing this particular error/exception, but simply knew that I don't want
> the Plugin to serialize the hibernateLazyInitializer instances in my entities. 
> The Plugin supports property exclusion via regex, thus the simple fix.
> 
> Hey, perhaps this property exclusion property will come in handy to keep from
> loading the whole database into memory for those self joins I have on my
> entities... :P.
> 
> On another note, although this fixes my particular issue, perhaps there is some
> more elegant solution to help with anything implementing this (or other
> problematic) OOP patterns.
> 
> -Nate
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

_________________________________________________________________
Bing™ brings you maps, menus, and reviews organized in one place. Try it now.
http://www.bing.com/search?q=restaurants&form=MLOGEN&publ=WLHMTAG&crea=TXT_MLOGEN_Local_Local_Restaurants_1x1

Re: Struts2 + JPA + JSON - Help with error

Posted by Nathan Schulte <na...@ngc.com>.
Nathan Schulte <nathan.schulte <at> ngc.com> writes:

> 
> Nathan Schulte <nathan.schulte <at> ngc.com> writes:
> > here, http://article.gmane.org/gmane.comp.jakarta.struts.user/170543,
> http://article.gmane.org/gmane.comp.jakarta.struts.user/170543
> 
> > Here is a link to the error, http://pastebin.com/m5d0d22c8.
> http://pastebin.com/m5d0d22c8
> 
> Also, here is the exception report (of a similar action) given as the HTTP
> response:
> http://pastebin.com/m21348ec5
> 

I have found a fix for this issue.  As it turns out, because the JSON Plugin is
using reflection, and the entities the JSON Plugin is reflecting on are using
Hibernate/JPA "lazy initialization magic", the JSON Plugin was serializing the
"magic" as well.  This "magic" contains references to underlying JPA
implementation, which also contains references, which also contain references,
all the way down past the JDBC layer.  I didn't go as far as to find out what
was causing this particular error/exception, but simply knew that I don't want
the Plugin to serialize the hibernateLazyInitializer instances in my entities. 
The Plugin supports property exclusion via regex, thus the simple fix.

Hey, perhaps this property exclusion property will come in handy to keep from
loading the whole database into memory for those self joins I have on my
entities... :P.

On another note, although this fixes my particular issue, perhaps there is some
more elegant solution to help with anything implementing this (or other
problematic) OOP patterns.

-Nate




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2 + JPA + JSON - Help with error

Posted by Nathan Schulte <na...@ngc.com>.
Nathan Schulte <nathan.schulte <at> ngc.com> writes:
> here, http://article.gmane.org/gmane.comp.jakarta.struts.user/170543,
http://article.gmane.org/gmane.comp.jakarta.struts.user/170543

> Here is a link to the error, http://pastebin.com/m5d0d22c8.
http://pastebin.com/m5d0d22c8

Also, here is the exception report (of a similar action) given as the HTTP
response:
http://pastebin.com/m21348ec5


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org