Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: Release 1.3.2, Release 1.4
-
Fix Version/s: Release 1.5
-
Component/s: None
-
Labels:None
-
Environment:Win32/JDK1.5
Description
Re-titling issue. The original problem (converting hibernate proxied objects) has been fixed with an arguably simpler solution for 1.4.1. See STS-264.
However, the possibility to exclude properties by name is also something that would be useful independent of hibernate, so I'm leaving this targetted for 1.5 with that purpose in mind.
--------------------------------------------------------------------------------------------------
If an object is loaded via Hibernate and then passed to the JavaScriptBuilder, it throws various exceptions.
See http://article.gmane.org/gmane.comp.java.stripes.user/769/ for a report of the error - to summarize:
(continued from above)
example stack trace:
> The stack trace:
>
> net.sourceforge.stripes.exception.StripesRuntimeException: Could not
> build JavaScript for object. An exception was thrown while trying to
> convert a property from Java to JavaScript. The object being converted
> is: com.kembuco.autotracker.model.Automobile <at> b36ee3db
> at net.sourceforge.stripes.ajax.JavaScriptBuilder.build(JavaScriptBuilder.java:154)
> at net.sourceforge.stripes.ajax.JavaScriptResolution.execute(JavaScriptResolution.java:50)
> at net.sourceforge.stripes.controller.DispatcherServlet.doPost(DispatcherServlet.java:168)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
The problem here is that rather than exporting the actual object the loaded object is enhanced by Hibernate with a variety of internal attributes that don't export properly for various reasons.
Rather than suggesting that we specifically make Stripes work with Hibernate, I'd suggest that a simple generic interface be supported to allow the caller to suppy an arbitrary algorithm for excluding properties.
I have attached a patch which illustrates an implementation of this which allows Hibernate objects to export correctly simply by ignoring the internal hibernate properties by excluding them by name.
Using this patch, Hibernate objects can be passed to JavaScriptBuilder successfully with a construct like:
return new JavaScriptResolution(hibnerateObject, new ExcludeByName(new String[] { "callback", "callbacks", "hibernateLazyInitializer" }));
Hope this is helpful. I think it's important for Stripes to be able to send back Hibernate objects as Javascript.
(see separately attached patch file)