Я использую Spring Boot / Spring Data JPA (Hibernate).У меня есть две сущности, WorkOrder
и Inspection
.WorkOrder
может иметь несколько Inspection
с, но Inspection
может быть привязано только к одному WorkOrder
.Когда у WorkOrder
есть один или несколько Inspection
с, должна быть некоторая дополнительная информация, поэтому я также создал сущность WorkOrderInspection
.Ниже приведены классы.С этой конфигурацией я получаю исключение отображения Hibernate:
отображение поврежденного столбца для: workOrderInspection.id из: com.couplingcorp.qualitycontrol.domain.inspections.Inspection
Что мне нужно изменить, чтобы исправить ошибку?Или есть лучший способ сопоставить это в целом?
WorkOrder
@Entity
@Table(name="manufacturing.workorders")
public class WorkOrder implements Serializable, Comparable<WorkOrder> {
private int workOrderID;
private List<WorkOrderInspection> inspections = new ArrayList<>();
...
@Id
@Column(name="pk_workorderid")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getWorkOrderID() {
return workOrderID;
}
public void setWorkOrderID(int workOrderID) {
this.workOrderID = workOrderID;
}
...
@OneToMany(mappedBy="workOrder",cascade=CascadeType.ALL,orphanRemoval=true)
public List<WorkOrderInspection> getInspections() {
return inspections;
}
public void setInspections(List<WorkOrderInspection> inspections) {
this.inspections = inspections;
}
}
Inspection
@Entity
@Table(name="qualitycontrol.inspections")
public class Inspection implements Serializable {
...
private int inspectionID;
private WorkOrderInspection workOrderInspection;
...
@Id
@Column(name="pk_inspectionid")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getInspectionID() {
return inspectionID;
}
public void setInspectionID(int inspectionID) {
this.inspectionID = inspectionID;
}
...
@OneToOne(mappedBy="inspection")
public WorkOrderInspection getWorkOrderInspection() {
return workOrderInspection;
}
public void setWorkOrderInspection(WorkOrderInspection workOrderInspection) {
this.workOrderInspection = workOrderInspection;
}
}
WorkOrderInspection
@Entity
@Table(name="manufacturing.workorders_inspections")
@IdClass(WorkOrderInspectionID.class)
public class WorkOrderInspection implements Serializable {
private static final long serialVersionUID = 1L;
private WorkOrder workOrder;
private Inspection inspection;
private int dwgXPosition;
private int dwgYPosition;
public WorkOrderInspection() {
}
@Id
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="fk_workorderid", referencedColumnName="pk_workorderid")
public WorkOrder getWorkOrder() {
return workOrder;
}
public void setWorkOrder(WorkOrder workOrder) {
this.workOrder = workOrder;
}
@Id
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="fk_inspectionid", referencedColumnName="pk_inspectionid")
public Inspection getInspection() {
return inspection;
}
public void setInspection(Inspection inspection) {
this.inspection = inspection;
}
@Column(name="dwgxposition", columnDefinition="decimal(4,0)")
public int getDwgXPosition() {
return dwgXPosition;
}
public void setDwgXPosition(int dwgXPosition) {
this.dwgXPosition = dwgXPosition;
}
@Column(name="dwgyposition", columnDefinition="decimal(4,0)")
public int getDwgYPosition() {
return dwgYPosition;
}
public void setDwgYPosition(int dwgYPosition) {
this.dwgYPosition = dwgYPosition;
}
@Override
public int hashCode() {
int hash = 5;
hash = 97 * hash + Objects.hashCode(this.workOrder);
hash = 97 * hash + Objects.hashCode(this.inspection);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final WorkOrderInspection other = (WorkOrderInspection) obj;
if (!Objects.equals(this.workOrder, other.workOrder)) {
return false;
}
if (!Objects.equals(this.inspection, other.inspection)) {
return false;
}
return true;
}
}
WorkOrderInspectionID
public class WorkOrderInspectionID implements Serializable {
private static final long serialVersionUID = 1L;
private WorkOrder workOrder;
private Inspection inspection;
public WorkOrderInspectionID() {}
public WorkOrderInspectionID(WorkOrder workOrder, Inspection inspection) {
this.workOrder = workOrder;
this.inspection = inspection;
}
public WorkOrder getWorkOrder() {
return workOrder;
}
public void setWorkOrder(WorkOrder workOrder) {
this.workOrder = workOrder;
}
public Inspection getInspection() {
return inspection;
}
public void setInspection(Inspection inspection) {
this.inspection = inspection;
}
@Override
public int hashCode() {
int hash = 7;
hash = 97 * hash + Objects.hashCode(this.workOrder);
hash = 97 * hash + Objects.hashCode(this.inspection);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final WorkOrderInspectionID other = (WorkOrderInspectionID) obj;
if (!Objects.equals(this.workOrder, other.workOrder)) {
return false;
}
if (!Objects.equals(this.inspection, other.inspection)) {
return false;
}
return true;
}
}