Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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
JPA:只有一个来自组合键的外键_Jpa_Orm_Composite Key - Fatal编程技术网

JPA:只有一个来自组合键的外键

JPA:只有一个来自组合键的外键,jpa,orm,composite-key,Jpa,Orm,Composite Key,我很难在JPA2/Hibernate中使用复合主键和外键。我试图用a和B创建一个简单的场景: CREATE TABLE Customer( customer_id uuid, employee_id int, created_at timestamp with time zone DEFAULT now(), CONSTRAINT customer_id_employee_id_pkey PRIMARY KEY (customer_id, employe

我很难在JPA2/Hibernate中使用复合主键和外键。我试图用a和B创建一个简单的场景:

CREATE TABLE Customer(
    customer_id uuid,
    employee_id int,
    created_at timestamp with time zone DEFAULT now(),
    
    CONSTRAINT customer_id_employee_id_pkey PRIMARY KEY (customer_id, employee_id),
    CONSTRAINT fk_owner_owner_id FOREIGN KEY (customer_id)
        REFERENCES public.owner (id) MATCH SIMPLE
        ON UPDATE CASCADE
        ON DELETE CASCADE
)
我应该如何创建实体类

我在下面试过了

@EqualsAndHashCode
@Data
public class CustomerId implements Serializable {
    private UUID customerId;
    private Long employeeId;
}


@Data
@Entity
@IdClass(CustomerId.class)
@Table(name = "customer")
public class Customer implements Serializable {
    private static final long serialVersionUID = -234295442215152987L;

    @Id
    @Column(name = "customer_id")
    private UUID customerId;

    @Id
    @Column(name = "employee_id")
    private Long employeeId;

    @CreationTimestamp
    @Column(name = "created_at", insertable = false, updatable = false)
    private OffsetDateTime createdAt;
}
但是我不确定应该在哪个类中映射customer_id,这是一个外键。
请帮帮我,应该是这样的

@Data
@Embeddable
public class CustomerId implements Serializable {
    private UUID customerId;
    private Long employeeId;
}


@Data
@Entity
@Table(name = "customer")
public class Customer implements Serializable {
    private static final long serialVersionUID = -234295442215152987L;

    @EmbeddedId
    @Column(name = "customer_id")
    private CustomerId customerId;


    @CreationTimestamp
    @Column(name = "created_at", insertable = false, updatable = false)
    private OffsetDateTime createdAt;
}