Cascade update problem

Hello everyone,

I’m having some issues about updating an object from an external webapp.

I need to update an object that contains nested object (some are even a list of nested objects) and the native axelor end-point updates only the parent object.

For example, if i have a Person that contains Address and a list of Planning, using the documentation update endpoint, it will only update the Person informations, not the Address nor Planning.

Also, i tried to create a custom endpoint using the JPA library available in Axelor. I also have issues using these methods as i encounter a Constraint Unique Key Violation for the nested objects.

For exemple, for the same Person as before, on update, the console says that the id already exists. BUT! The thing is, it looks like it creates a new line in the database (eventhough it doesn’t) as the id of the address is id = 2 and the error says that the id = 3 already exists. If i run the update once again, the console indicates that the id = 4 already exists (which doesn’t by the way).

I checked the generated domain classes, but the annotations for the @OneToMany or the @ManyToMany contains the rights properties :

fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE }

for the JPA update cascade to occur (at lest in pure Java style).

Do you have anything that could help me? We use the 5.1.2 version of Axelor.

Thanks a lot!

UPDATE: When i use the same method using a completely new JSON body (Person, address, list of planning), i actually get the same Constraint Violation error…
Precision, i’m using :


As decorators for my Controller method, endpoint which i call via Postman using a JSON as a body.
I tried as well using the @POST decorator instead of @PUT (out of despair), got the same error message.

Hey, some kind of update for this issue.
So i’m actually trying to fix it up by doing updates on child object before updating the parents, but i’m not entirely sure that it will work. I mean, i don’t know if i can for sure update the parent and not update the childrens.

UPDATE: Soooooo…
When i try to do the update on the children, i have something interesting (annoying is more appropriate).
For example, i try to modify an attribute (name) of an object “Organisme”. The id does exists and is given to the entity object, here is the response:

result: "Organisme{id=10641, name=OrganismeModif}" entity: "Organisme{id=10612, name=OrganismeModif}"

And then, a new line is created, eventhough it goes into the process of

T result = em().merge(entity);

Which doesn’t make any sense. He should not create a new line if it goes inside merge method instead of persist method.

I just compared with what Axelor is doing himself when updating datas and he goes through the persist method instead of the merge method. I’m confused and lost.

Help is strongly required here please…

So i found a solution to my issue.
It looked like i was doing something wrong with the version on the object i sent. Looks like you ABSOLUTELY MUST send the version (eventhough it was my first guess and tried).
PLUS, it actually works with the native REST axelor end point.
Thank you for the help. :+1:


Glad to see you resolved it.

Just a kind reply for the some explanations about rest API : when updating a record, you need at least send the id (that makes sense) AND the version. The version should matched the current record version else it will throw an exception. This ensure that the record haven’t be updated in the meantime and you are updating the right data.
Note that at each save of a record, the version field is incremented.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.