外键列数错误

时间:2018-08-22 06:39:17

标签: jpa one-to-many entity-relationship

我发现了很多与此主题有关的问题,但没有一个给我答案。 我有一个表InstructionSignature,它与另一个表Staff具有一对多的关系。此关系是单向的,因此表Y与X没有关系。这是实体:

这是Staff实体,不拥有InstructionSignature

@Entity
@Table(name="T_STAFF")
@Data
public class Staff {

@EmbeddedId
private StaffPK id;

@MapsId("userId")
@ManyToOne
@JoinColumn(name="USER_ID")
private MdUser user;

@MapsId("orderUuid")
@ManyToOne
@JoinColumn(name="ORDER_UUID")
private LoadOrders loadOrders;

@Column(name="RETURN_REQUEST",
        nullable=false)
private Integer returnRequest;

@Column(name="RELEASE_REQUEST",
        nullable=false)
private Integer releaseRequest;

@Column(name="SCHED_BEGIN",
        columnDefinition="char")
private String schedBegin;

@Column(name="SCHED_END",
        columnDefinition="char")
private String schedEnd;

@Column(name="PADILOS_ORDERID")
private String padilosOrderId;

@Column(name="PADILOS_MESSAGEID")
private String padilosMessageId;

@Column(name="PREVIOUS_POSITION")
private String previousPosition;

@Column(name="PREVIOUS_POSITION_TS",
        columnDefinition="char")
private String previousPositionTs;

private String bel;

@Column(name="ONPOSITION_TIME",
        columnDefinition="char")
private String onPositionTime;

private String activities;

@Column(name="DESIGNATED_SUPERVISOR",
        nullable=false)
private Character designatedSupervisor;

@Column(name="CLIENT_ENABLED",
        nullable=false)
private Character clientEnabled;

@Column(name="LAST_READ_MSG",
        columnDefinition="char")
private String lastReadMsg;


@OneToMany(fetch=FetchType.LAZY)
@JoinColumns({
    @JoinColumn(name="ORDER_UUID"),
    @JoinColumn(name="USER_ID")
})
private List<Equipment> equipments;

@OneToMany(fetch=FetchType.LAZY)
@JoinColumns({
    @JoinColumn(name="ORDER_UUID"),
    @JoinColumn(name="USER_ID")
})
private List<OrderTime> orderTimes;

@OneToMany(fetch=FetchType.LAZY)
@JoinColumns({
    @JoinColumn(name="ORDER_UUID"),
    @JoinColumn(name="USER_ID")
})
private List<StaffRole> staffRoles;

@OneToMany(fetch=FetchType.LAZY)
@JoinColumns({
    @JoinColumn(name="ORDER_UUID"),
    @JoinColumn(name="USER_ID")
})
private List<StaffStates> staffStates;
}

这是具有单向一对多关系的InstructionSignature

@Entity
@Table(name="T_AL_INSTR_SIGNATURE")
@Data
public class AlInstructionSignature {

@EmbeddedId
private AlInstructionSignaturePK id;

@MapsId("instructionsPk")
@ManyToOne
@JoinColumns({
    @JoinColumn(name="ORDER_UUID"),
    @JoinColumn(name="EDITION_NUMBER")
})
private AlInstructions instructions;

@OneToMany(fetch=FetchType.LAZY)
@JoinColumns({
    @JoinColumn(name="STAFF_ORDER_UUID"),
    @JoinColumn(name="STAFF_USER_ID")
})
private List<Staff> staff;

@Column(nullable=false)
private String prompt;

@Column(name="SIGNED_AT",
        columnDefinition="char")
private String signedAt;

@Lob
@Column(name="E_SIGNATURE")
private byte[] eSignature;
}

[编辑] 这是PK类:

@Embeddable
@Data
public class AlInstructionSignaturePK implements Serializable {

private static final long serialVersionUID = 5238757055555206421L;

private AlInstructionsPK instructionsPk;

private String id;

public AlInstructionSignaturePK() {

}

public AlInstructionSignaturePK(AlInstructionsPK instructionsPk, String id) {
    this.instructionsPk = instructionsPk;
    this.id = id;
}
}


@Embeddable
@Data
public class StaffPK implements Serializable{

private static final long serialVersionUID = -1671872364052569359L;

@Column(name="ORDER_UUID")
private String orderUuid;

@Column(name="USER_ID")
private String userId;

public StaffPK() {

}

public StaffPK(String orderUuid, String userId) {
    this.orderUuid = orderUuid;
    this.userId = userId;
}
}

[编辑]

在InstructionSignature上执行操作时,出现此异常:

Caused by: org.hibernate.AnnotationException: A Foreign key refering de.XXX.XXX.XXX.data.entity.AlInstructionSignature from de.XXX.XXX.XXX.data.entity.Staff has the wrong number of column. should be 3

我错了吗?还是该异常告诉我,JPA意味着从Staff到InstructionSignature都有一个ForeignKey?如果不是,那么InstructionSignature中的外键有什么问题? Staff的组合键包含两列,而不是三列。有人可以帮我吗?

0 个答案:

没有答案