How to load lazy loaded objects in JSON?

Hi,

 

I had a problem a while ago i got row updated or deleted error. I found out what my problem was, i checked the always load objects radio button, in the Business Data Modell editor and had a structure like this:

Owner

Car

Wheel

 

The Owner has multiple Car objects, and the Car objects has multiple wheel objects. If i set this to always load objects, then in the entity the connection between these objects will be eager. When i try to modify one Car then since it is set to eager it will version the wheels as well. And if i try to modify another car with the same wheel at the same time, then the row was updated or deleted error kicks in. 

But if i turn the always load to only load objects when needed, then it will work fine, since it wont version the wheels just because i changed the car.

Now that i understand how this works, i have my question that will probably make sense, on my forms i took advantage of the eager loading. If i turn it to only load... then my forms wont work because my owners will only have a link for the cars, and then the cars will also have a link to the wheels.

My question is what could you advise? What is the best solution to make my forms work if i for example wanted to show the user a list of cars with the wheels at the same time? Is there a way to do it? Normally i would have a link for the wheels, but if i have multiple cars then it isnt easy and also not efficient to load all those links at the same time. If i have 50 cars with 4 wheels each, then it would call the server 200 times in a row.

Is there an efficient way to do this? I thought of creating my own API extension, that creates a response with the full JSON like it was an always load connection. But then i have to make one for all my calls.

Or maybe is there a way to configure the Jackson? (i think Bonita uses Jackson) So that it gives back even the lazy loaded objects as JSON?

 

 

Hello,

Updating objects should work for both EAGER / LAZY relations, it's transparent

If you get errors or weird behaviors when you update an object that is in eager relation you should understand the stacktrace.

Is it a development error? is it a product issue?

About choosing between EAGER/LAZY, as a rule of thumb you can try to use EAGER first and do a call on the parent object, and see the size of the response (Bare in mind that in production data can be different). If it's acceptable then go for that. If it's too big go for LAZY.

Writing a form representing object with lazy relations is a bit more complicated because you need to do several calls.

Hope it helps, cheers.

The problem with the eager method is that it has cascade set to MERGE, this means if the parent is updated then the child will be also updated, and with the update the version is also updated. If two process instances start on the same exact time, and the business data object has the same child in both, then the first to finish will version the child even though only the parent was modified.

This is a really easily to set up error, although this is not Bonita error, it is simply bad use of the lazy/eager setting. If you create a process that has a timer set to 1:00PM and start 5 process instances that will trigger at 1:00PM, this way all 5 objects will be modified at the same time, and the first will succeed. The other 4 wont, because the child was versioned +1 in the first modification. 

This is not really the EAGER/LAZY setting, when you set always load objects, then in the generated entity the annotation will be cascade=Cascade.MERGE, and this setting is that will tell the system to version the child objects, not the EAGER alone.

Also i found out by reading a lot of documentations and trying out examples, that the only workable way, that is native Bonita to use Rest API extension-s if you have to use LAZY loading. 

In summary, i will not close this question because there might be someone who can advise something better :) But i already did a lot of research and i think if you have a lot of data with many levels, and a lot of processes using those data in parallel, then you need to use LAZY loading (in Bonita at least).

Just to show you what im talking about:

Client has Many vehicles, and vehicles has many vehicleServices, and vehicleServices has one product

So the product is at the bottom of the 4. Level.

If i use EAGER then even if i modify just the client, the product will be versioned (persistenceVersion will be x+1)