We use Flex with a Java back end, and an O/R framework.

Our Java classes naturally contain properties which are relationships to other classes -
either one to many or many to one.  Due to the fact that these relationships are so
intertwined, many given objects end up referencing a large portion of the database if one
were to recursively follow all of the nested relationships.  As such, we desire to have the
option of not loading certain relationships when the data is not needed.

We use EJB 3.0 (JBoss implementation using Hibernate) as our O/R framework for object
persistence.  It allows the option of uninitialized collections and other referenced objects. 
But it keeps it's eye on those uninitialized objects in case you access them.  It will load
them at that time.

The Flex process of serialization to AMF causes serious problems for this design.  Since
Flex tries to touch all of these properties while building the binary representation for
sending over the wire, it triggers the immediate attempt to initialize any objects which are
still in the uninitialized state.

This causes the LazyInitializationException to be thrown by the O/R framework - because
the transaction is already closed (which effectively means the call to the DAO has
returned).

The community only offers two suggestions, both which do not work with Flex (or Flash
Remoting for that matter). 

The first is simply initializing everything ahead of time.  This does not work because
eventually you have to draw the line somewhere, and the Flex serialization routines will
find that line and try to cross it. 

The second is the open session in view pattern, meaning that we open the transaction as
soon as the Flex client makes a request, and close it only when the last response has been
made.  This does not work either, because Flex would end up initializing everything during
serialization - which is what we're trying to avoid in the name of performance and
efficiency.

I have gone to the extent to writing a custom aspect to intercept returning calls from my
DAO and null out the Hibernate proxies.  This worked until I tried to use it for uninitialized
many to one relationships.  Nulling them out actually deletes my relationship in the
database!

Carbon Five wrote a utility for Flash Remoting which would create ASObjects as return
values from a Java application.  They implemented a concept of adding certain properties
to an ignore list.  This solved our problem when we used Flash Remoting, but was very
cumbersome to use.  This ignore list had to be built by hand in each function.  Later Flash
Remoting was improved seemingly by adding ASTranslator to the product, which lessened
the need for this third party library, but working with the ignore list was not exposed.

The only good solution I see is to add intelligence to the Flex serialization techniques
which watch for the scenario of uninitialized arrays and object which come from
relationships, and avoid triggering the lazy initialization.  Maybe Adobe would consider
helping out with this?

Any other suggestions would be greatly appreciated.






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to