Невозможно обновить сущность JPA с отсоединенной сущностью (используя JSON) - PullRequest
0 голосов
/ 11 февраля 2019

У меня есть объект под названием Faculty, который имеет ассоциацию ManyToOne с отделами (CasCadeType = DETACHED), после отдельного сохранения отдела и факультета (без отдела) я хочу обновить факультет с отделом, но я получаю исключение ниже.Я использую CrudReposiotry для выполнения операции.Нужна помощь с этим или любым другим способом сделать это.

org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [com.sumeeth.api.smsmodel.model.faculty.Faculty#1]
        at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:321) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
        at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:170) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
        at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:69) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
        at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:901) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
        at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:887) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]

Я могу выполнить это с помощью junit, но я сталкиваюсь с проблемой, когда я делаю это с помощью Restcontroller (данные json)

{
    "id": 1,
    "version": 1,
    "createDt": "2019-02-10T17:12:47.000+0000",
    "modifiedDt": "2019-02-10T20:48:44.000+0000",
    "createdBy": "SYSTEM",
    "updatedBy": "SYSTEM",
    "isActive": true,
    "comment": "jjj",
    "facultyId": 100,
    "personAttributes": {
        "id": 1,
        "version": 1,
        "createDt": "2019-02-10T17:12:47.000+0000",
        "modifiedDt": "2019-02-10T17:14:15.000+0000",
        "createdBy": "SYSTEM",
        "updatedBy": "SYSTEM",
        "isActive": true,
        "comment": null,
        "fName": "Saktiman",
        "mName": "JUNIT",
        "lName": "JUNIT",
        "contactId": {
            "id": 1,
            "version": 0,
            "createDt": "2019-02-10T17:12:47.000+0000",
            "modifiedDt": null,
            "createdBy": "SYSTEM",
            "updatedBy": null,
            "isActive": true,
            "comment": null,
            "primaryEmail": null,
            "secondaryEmail": null,
            "primaryPhone": {
                "id": 1,
                "version": 0,
                "createDt": "2019-02-10T17:12:47.000+0000",
                "modifiedDt": null,
                "createdBy": "SYSTEM",
                "updatedBy": null,
                "isActive": true,
                "comment": null,
                "mobileNo": 0,
                "landLine": {
                    "id": 1,
                    "version": 0,
                    "createDt": "2019-02-10T17:12:47.000+0000",
                    "modifiedDt": null,
                    "createdBy": "SYSTEM",
                    "updatedBy": null,
                    "isActive": true,
                    "comment": null,
                    "landLineNo": 1234,
                    "stdCode": 222
                }
            },
            "secondaryPhone": null
        },
        "permanentAddress": null,
        "correspondenceAddress": null,
        "dob": "2019-02-09T22:21:36.000+0000",
        "sex": "MALE"
    },
    "doj": "2019-02-09T22:21:36.000+0000",
    "departments": [ {
        "id": 2,
        "version": 0,
        "createDt": "2019-02-10T20:50:55.354+0000",
        "modifiedDt": null,
        "createdBy": "SYSTEM",
        "updatedBy": null,
        "isActive": true,
        "comment": null,
        "deptName": "Information Technology",
        "deptCode": "IT",
        "hod": null,
        "faculties": null,
        "school": null
    }],
    "school": null,
    "userId": null
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...