Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Hibernate中为多个One引用处理分配的Id_Java_Hibernate_Spring Data Jpa_Nhibernate Mapping - Fatal编程技术网

Java 如何在Hibernate中为多个One引用处理分配的Id

Java 如何在Hibernate中为多个One引用处理分配的Id,java,hibernate,spring-data-jpa,nhibernate-mapping,Java,Hibernate,Spring Data Jpa,Nhibernate Mapping,我有两个像下面这样的实体-一个具有自动生成的ID,另一个具有分配的ID。 受让人的Id是从请求发送的。 我和他们之间有很多种关系。但当我插入时,它显示以下错误 "org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing: com.example.entity.Tas

我有两个像下面这样的实体-一个具有自动生成的ID,另一个具有分配的ID。 受让人的Id是从请求发送的。 我和他们之间有很多种关系。但当我插入时,它显示以下错误

"org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing: com.example.entity.Task.assignee->com.example.entity.Assignee
下面是我的类和注释

package com.example.entity;
    @Data
    @Entity
    public class Task {
        @GeneratedValue(generator = "system-uuid")
        @Id
        private UUID id;
        private String name;
        private String description;
        @ManyToOne(cascade = CascadeType.ALL)
        @JoinColumn(name = "assignee_id")
        private Assignee assignee;
    }

   
package com.example.entity;
    @Data
    @Entity
    public class Assignee implements Persistable<UUID> {
        @Id
        private UUID id;
        private String name;

    
        
        @OneToMany(mappedBy = "assignee",fetch = FetchType.LAZY)
        private List<Task> tasks = new ArrayList<>();

        @Transient
        private boolean isNew = true;
    
        @Override
        public boolean isNew() {
            return isNew;
        }
    
        @PrePersist
        @PostLoad
        void markNotNew() {
            this.isNew = false;
        }
    }
正如我所说,task-has自动生成了ID,其中as受让人ID是从这个API的调用方发送的。但当我调用存储库的save方法时,会出现以下异常。拯救受让人是一种抱怨,但我已经放弃了一切 在实体的映射中

org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing: com.example.entity.Task.assignee->com.example.entity.Assignee

请提供更多代码/数据/信息。@xerx593提供了所有详细信息。我认为您做错了,为什么要创建assignee,然后将其添加到任务中?受让人
Id
来自哪里?这不是你数据库里的吗?我就是这么说的。受让人-已分配Id-未生成其Id。我不想在我的应用程序中生成它。基本上,受让人是用户,前端服务从其他微服务获取信息,然后发送给我。
{
    "name": "test task",
    "description": "Do this task man",
    "assignee": {
        "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
        "name": "Lucia"
    }
}
org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing: com.example.entity.Task.assignee->com.example.entity.Assignee