API Update Entity with Composition Entities

This used to work, I don’t know if it’s an issue from a previous update. I have a Ticket with a composition child collection of Steps.

API Process:

  1. Create new TIcket + Steps with single message to API
  2. Select Ticket (with Steps) from API
  3. Update a field on a Step Message and Send Ticket + Steps to API to update step.
  4. Error, Step doesn’t have a reference back to ticket in the API, but I’m getting “Cannot get unfetched attribute [ticket] from detached object com.company.njuns.entity.Step-d0f7c0e2-e62d-1953-4674-94f9cf165071 [detached].”

I have no way of specifying the view, and this error I found EntityImportExport: 409. This service is trying to add the reference of Step back to Ticket but it can’t do this.

Hi,

What is the platform version do you use? Could you provide sample project?

I couldn’t reproduce the problem. I have tested on the 6.9.5 version.

Data model:

@NamePattern("%s|number")
@Table(name = "UBERJAR_TICKET")
@Entity(name = "uberjar$Ticket")
public class Ticket extends StandardEntity {
    private static final long serialVersionUID = -5708688890287368172L;

    @Column(name = "NUMBER_")
    protected String number;


    @Composition
    @OnDelete(DeletePolicy.CASCADE)
    @OneToMany(mappedBy = "ticket")
    protected List<Step> steps;

    //getters and setters
}

@NamePattern("%s|name")
@Table(name = "UBERJAR_STEP")
@Entity(name = "uberjar$Step")
public class Step extends StandardEntity {
    private static final long serialVersionUID = -647301058479062547L;

    @Column(name = "NAME")
    protected String name;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "TICKET_ID")
    protected Ticket ticket;

    //getters and setters
}

JSON request body:

{
    "_entityName": "uberjar$Ticket",
    "_instanceName": "ticket",
    "id": "c88791f7-bd14-faba-854a-2de06d27cec1",
    "number": "ticket",
    "version": 1,
    "steps": [
        {
            "_entityName": "uberjar$Step",
            "_instanceName": "Step",
            "id": "c7cd0f89-cf39-cc46-1d8d-4345f2fb1006",
            "name": "Step111",
            "version": 1
        }
    ]
}

HI. I am currently experiencing exactly this same problem with REST API v7.2.6

Create entity with composition, query the json entity graph from the API, attempt to update that same json back to the API via PUT, and get unfetched attribute on the child item property that points back to the parent.

Did you ever find the cause?

Hello,

I’ve tried to reproduce the issue on 7.2.6 but had no luck.

Here is my project :
restupdateworks.zip (101.6 KB)

Json sent via PUT to http://localhost:8080/app/rest/v2/entities/restupd_MainEntity/571ac196-d64f-0987-c5da-41d66c1b4c1a

    {
        "_entityName": "restupd_MainEntity",
        "_instanceName": "One",
        "id": "571ac196-d64f-0987-c5da-41d66c1b4c1a",
        "childEntities": [
            {
                "_entityName": "restupd_ChildEntity",
                "_instanceName": "ChildTwo",
                "id": "4d3c491f-5a97-3487-7c49-52ab31c86f7c",
                "mainEntity": {
                    "id": "571ac196-d64f-0987-c5da-41d66c1b4c1a"
                },
                "name": "ChildTwo",
                "details": "2_updated"
            },
            {
                "_entityName": "restupd_ChildEntity",
                "_instanceName": "ChildOne",
                "id": "38ad0ac4-70da-21b7-88e6-ad2c2c21628c",
                "mainEntity": {
                    "_entityName": "restupd_MainEntity",
                    "_instanceName": "One",
                    "id": "571ac196-d64f-0987-c5da-41d66c1b4c1a"
                },
                "name": "ChildOne",
                "details": "1_updated"
            }
        ],
        "createdBy": "admin",
        "name": "One",
        "createTs": "2024-04-26 19:54:53.840",
        "details": "some details [updated]",
        "version": 1,
        "updateTs": "2024-04-26 19:54:53.840"
    }

In order to investigate the issue, please, provide

  1. example project to reproduce the issue,
  2. full stacktrace of the exception.

Regards
Dmitry