Skip navigation
Flavy85
Currently Being Moderated

How to use createItem via DataServiceTransaction-API correctly

Mar 3, 2012 4:18 AM

Tags: #lcds #entity #modeler #dataservice #dataservicetransaction #unsaved #createitem

Hello,

 

I try to create an item via the DataServiceTransaction-API:

 

DataServiceTransaction dtx = DataServiceTransaction.begin(false);

dtx.setSendChangesToAdapter(true);

 

EntityA a = new EntityA();

EntityB b = new EntityB();

a.setEntityB(b);

 

dtx.createItem(EntityA.class.getName(), a);

dtx.commit();

 

When I call this serivce from my FlexClient an error occurred, wich says that EntityB is unsaved!

 

I know why this erro happens but really dont't know how to fix that.

 

Is there any way to make the creation cascading(from the modeler-plugin within FlashBuilder)?

 

or

 

Do i have to create the "child"-properties on my own via another call of "dtx.createItem" with EntityB? If so, how can I check the DataService for the entity, if the entity already exists? via a fill operation? how do call that manually?

       

I know question over question!

 

Hope you can help me out!

 

Cheers

Flavy

 
Replies
  • Currently Being Moderated
    Mar 6, 2012 6:55 AM   in reply to Flavy85

    Hi

     

    If using a Transactional data source with a model you to specify the hibernate.transaction.factory_class and hibernate.transaction.manager_lookup_class properties as appropriate for your server and then call DST with useJTA set to true.

     

    See here: http://help.adobe.com/en_US/dataservicesjee/4.6/Modeling/WSa53bf8bf818 9e60776c71f0d133f0350afe-8000.html

     

    Specifically for Tomcat, the below values should work:

     

     

     

    Data Services does not support cascade operations on associations. You should save EntityB and then (in the same transaction) save EntityA.

     

    Regards,

     

    Ashish Vashisht

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 6, 2012 6:58 AM   in reply to Flavy85

    Hi

     

    Sorry about that, the forums seem to be losing the value. You can find it here:

     

    http://forums.adobe.com/message/4217327#4217327

     

    Regards,

     

    Ashish Vashisht

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 15, 2012 12:20 AM   in reply to Flavy85

    Can you post a snippet of your model, specifically the model level DMS annotation where you have set the above properties?

     

    With regards to whether EntityB is already saved or not, it is not possible to know without query the DB if the entity is already present. One common pattern that is followed in this case is to check if the ID is 0 (or some other pre-defined value) and then use that to infer that the item is unsaved,

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points