6 Replies Latest reply on Nov 11, 2011 6:17 AM by Ashish Vashisht

    How to use UpdateItem() in DataServiceTransaction

    RupakKhurana Level 1


      I am using the following code to push an entry to the client and also create a new one in the database. However subsequently I want to just update the previous entry with new volume and price. So I use the updateItem() as shown below.  Please note that the entry in the database is already present, I am just updating it as part of this test..


              DataServiceTransaction dtx = DataServiceTransaction.begin(false); 



              Positions p1 = new Positions();


              //p1.setPositionsId(new Integer(1));

              p1.setPositionsSymbol(new String(symbol));

              p1.setPositionsVolume(new Double(volume));

              p1.setPositionsPrice(new Double(price));

              p1.setPositionsServerTimestamp(new Date()); 


              //dtx.createItem("WorkStation.Positions", p1); 

              dtx.updateItem("WorkStation.Positions", p1, null, null); 




      It is however throwing an exception flex.messaging.MessageException at


      flex.data.DataService.sendBatchToAdapter(DataService.java 1630)





      Any ideas whats going wrong here...




        • 1. Re: How to use UpdateItem() in DataServiceTransaction
          Ashish Vashisht



          Can you post the full stack trace?


          I wanted to note, since you are storing data in the Database, I would recommend you start the DataServiceTransaction with the useJTA parameter set to true.




          Ashish Vashisht

          • 2. Re: How to use UpdateItem() in DataServiceTransaction
            RupakKhurana Level 1

            Exception: flex.messaging.MessageException:


                    at flex.data.DataService.sendBatchToAdapter(DataService.java:1630)


                    at flex.data.DataServiceTransaction.addProcessedMessage(DataServiceTransaction.java:2856)


                    at flex.data.DataServiceTransaction.updateItem(DataServiceTransaction.java:521)




            I am using useJTA=false even to add the entry to database, that seems to work correctly.




            I will try with useJTA=true…

            • 3. Re: How to use UpdateItem() in DataServiceTransaction
              RupakKhurana Level 1





              I tried with useJTA=true and got same exception while updating item…







              • 4. Re: How to use UpdateItem() in DataServiceTransaction
                RupakKhurana Level 1

                I tried deleteItemWithId() but same exception as updateItem(), there is something that I am doing wrong….

                • 5. Re: How to use UpdateItem() in DataServiceTransaction
                  RupakKhurana Level 1

                  I played around with the parameters.. It appears the arguments – previousVersion and Changes have to be non null? If I provide valid objects for newVersion ,previousVersion and changes, then the update happens..I should be able to supply them as null as per the docs below..




                  From the LCDS docs....




                  public void updateItem(String  destination,

                                        Object  newVersion,

                                        Object  previousVersion,

                                        String [] changes)


                  Send an update event to clients subscribed to this message. Note that this method does not send the change to the adapter/assembler - it assumes that the changes have already been applied or are being applied in this JTA transaction. It only updates the clients with the new version of this data.


                  You must supply a destination parameter and a new version of the object. If you supply a non-null previous version, this object is used to detect conflicts on the client in case the client's version of the data does not match the previous version. You may also supply a list of property names that have changed as a hint to the client to indicate which properties should be checked for conflicts and updated. If you supply null for the changes, all properties on the client are updated. These property names do not accept any kind of dot notation to specify that a property of a property has changed. Only top level property names are allowed.




                  destination - Name of the Data Management Services destination that is managing the item you want to update.


                  newVersion - New version of the item to update. The identity of the item is used to determine which item to update.


                  previousVersion - If not null, this contains a version of the item you intend to update. The client can detect a conflict if its version does not match the previousVersion. If you specify the value as null, a conflict is only detected if the client has pending changes for the item being updated.


                  changes - Array of property names which are to be updated. You can provide a null value to indicate that all property values may have changed.


                  Message was edited by: RupakKhurana

                  • 6. Re: How to use UpdateItem() in DataServiceTransaction
                    Ashish Vashisht Level 1

                    You should not have to supply the previousVersion. Can you ensure that when you send in the newVersion, it has its ID property set properly?


                    Besides that, can you check the server log to see what exception is being logged there?


                    If there is nothing in the server log, in the MessageException you are getting, there should be a extendedData property of type Map. Inside that Map, there should be a List of errorMessages. Can you check what ErrorMessage is present inside of that?