Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

How to use createItem via DataServiceTransaction-API correctly

Avatar

Former Community Member

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

7 Replies

Avatar

Former Community Member

To make it clear and short:

I just want to make a cascading creation!

THANKS!

Avatar

Former Community Member

Hey its me again

I notice that all the data I added via da DataServiceTransaction-Class via my custom service is lost when I Stop and Start the tomcat again!!

I configured a tomcat within FlashBuilder(eclipse) and Start/Stop it from there!

Any Ideas? I know, I am doing something wrong!

Avatar

Former Community Member

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/WSa53bf8bf8189e60776c71f0d133f0350afe-8000....

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

Avatar

Former Community Member

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

Avatar

Former Community Member

Hi Ashish,

thanks for your answer!

Does that mean, i just have to set these properties in my model if I want to create/update my datasource via the transaction-Api within my custom service?

How can I query the datasource,to know if i need a createItem for EntityB? I dont want to add EntityB with the same name property e.g?

Thanks

UPDATE:

When I set the properties like in the thread above(for tomcat), I cant deploy the model via the FlashBuilder! It says something like "Can't create Class of type "" ."(original Msg will be added soon )

UPDATE2:

Complete Error-Message:

Error creating and starting destinations while deploying model 'portal.Animal'.

Caused by: Cannot create class of type''.

(portal.Animal is a test-class)

I set the following properties in my model:



<item name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</item>


<item name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JOTMTransactionManagerLookup</item>

Avatar

Former Community Member

Has really nobody an idea for this problem?

Avatar

Former Community Member

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,