10 Replies Latest reply on Sep 17, 2009 2:24 PM by Ansury

    How to handle java Set on flex side.

    kminKeller-si5I0P Level 1

      I have a java service that returns me a Set type data. I cannot map this data at the flex end coz it blows out even it reaches the app and I get error message on the fault command.

       

      Is it that Flex cannot handle Set data?

       

      Any suggestion would be highly appreciated. Thanks.

        • 1. Re: How to handle java Set on flex side.
          Ansury Level 3

          Set, as in the Set interface with say for example a HashSet object?  Yes, this will work--I'm sending those from Java to Flex.  Are you using Blaze DS or Granite DS?  What is the error message in the fault response?

          • 2. Re: How to handle java Set on flex side.
            kminKeller-si5I0P Level 1

            Thanks for the quick response, Ansury.

             

            Yes I am using a HashSet on my java and I am using AMF Remote Objects.

             

            here is what the error message looks like: "testClass" is the class that the object is mapped to on flex and testSet is the HashSet and is a variable in that calss.

             

            ERROR = [FaultEvent fault=[RPC Fault faultString="failed to lazily initialize a collection of role: testClass.testSet, no session or session was closed" faultCode="Server.Processing" faultDetail="null"] messageId="5DB2C87F-AF2A-F4B2-1C16-EC3D58E1579E" type="fault" bubbles=false cancelable=true eventPhase=2]

             

            We are using hibernate and it is set to a lazy init mode.

             

            How can we map a HashSet on Flex end?

             

            Thanks.

            • 3. Re: How to handle java Set on flex side.
              Ansury Level 3

              That's a Java/Hibernate error, not really Flex related.  Let me think and see if I can recall how we fixed it, because we ran into 100% exactly the same thing at one point (crummy Hibernate).  I mostly work client side now so since it's a server side problem I'm not sure I can recall, we changed something Hibernate config related I believe.

              1 person found this helpful
              • 4. Re: How to handle java Set on flex side.
                kminKeller-si5I0P Level 1

                Thanks a lot Ansury. But when I debug the java side, I get the result back till the end return statement. it throws exception in between the java service and flex which I believe the error happens at the AMF transform layer. am I making any sense?

                 

                BTW, in the mean time, how do I map a java class with HashSet to Flex class? for instance:

                 

                java

                class test {

                int id:

                Set set= HashSet(0);

                }

                 

                to Flex class:

                [Bindable]
                [RemoteClass(alias="test")]

                class testVO {

                var i: int;

                ?????

                }

                 

                Thanks in advance.

                • 5. Re: How to handle java Set on flex side.
                  Ansury Level 3

                  We may have just disabled lazy init (if you do this does it go away?).  I believe the problem is that LCDS, Blaze or Granite (whatever you're using) are calling getters on your DTOs containing data which hibernate hasn't fetched from the database yet.  When Hibernate tries to do so, it's out of the scope of the original session that you used to get whatever data you actually do have, so the session is gone.

                   

                  If you're using Granite DS, I THINK they have a way of functioning in conjunction with Hibernate a little nicer for things like lazy init and such.  But it'd be more work setting things up (the opposite of what Hibernate is supposed to be doing for you, cut back on work...) -- and I've never tried it so I can't say how it is.

                  • 6. Re: How to handle java Set on flex side.
                    Ansury Level 3

                    kminKeller wrote:

                     

                    Thanks a lot Ansury. But when I debug the java side, I get the result back till the end return statement. it throws exception in between the java service and flex which I believe the error happens at the AMF transform layer. am I making any sense?

                     

                    BTW, in the mean time, how do I map a java class with HashSet to Flex class? for instance:

                     

                    java

                    class test {

                    int id:

                    Set set= HashSet(0);

                    }

                     

                    to Flex class:

                    [Bindable]
                    [RemoteClass(alias="test")]

                    class testVO {

                    var i: int;

                    ?????

                    }

                     

                    Thanks in advance.

                     

                    Yup, that makes sense and jives (ugh I hate that word) with what I posted above, the data services layer is trying to access uninitialized object(s) so it can send them to Flex.  At least that's the theory --I've yet to actually explore the actual data service code that is doing this to verify 100% but I'm fairly sure.

                     

                    A Set in Java is an ArrayCollection in ActionScript.

                    • 7. Re: How to handle java Set on flex side.
                      kminKeller-si5I0P Level 1

                      Thanks for all your help.

                       

                      But I am not convinced when you said a Set is an ArrayCollection in ActionScript. Set is a key value pair Collection and when you try to assign that to an ArrayCollection you get data coercion error. We are loosing data here coz my key consist of a list of array as value.

                       

                      Looks like we are missing something in the transformation layer on BlazeDS here. BalzeDS could not somehow handle HashSet data. Let me know if you find anything helpful. I am also trying to some research online.

                      • 8. Re: How to handle java Set on flex side.
                        Ansury Level 3

                        Are you sure you're not getting confused with a Map (i.e. HashMap)?  A set is simply a list that cannot have duplicate elements:

                         

                        http://www.j2ee.me/j2se/1.5.0/docs/api/java/util/Set.html

                         

                        A Map would be an Object in ActionScript.

                        • 9. Re: How to handle java Set on flex side.
                          kminKeller-si5I0P Level 1

                          Ah, I appologize. You are right.

                          • 10. Re: How to handle java Set on flex side.
                            Ansury Level 3

                            I think for the Hibernate issue we just called initialize() on the Set before returning it from our DAO.

                             

                            So even though this is not a Java forum:

                             

                            hibernateTemplate.initialize(modelToReturn.getSetWithinModel());

                             

                            I believe is how we got around this.  There's other ways too, Granite DS may offer a different solution, or you COULD also separate your model objects from your DTOs and return DTOs with only the data you want to send to Flex.  You'd probably have to copy that stuff over to your DTO manually though, unless you decided to use reflection or something to automate.  But that way these getters causing your error will never get called, and the Hibernate session won't need to be accessed anyway.

                            1 person found this helpful