我有一个表格投诉主文件,其中包含一个主键,该主键在另一个名为complaint_treatment的表中被用作外键,该表具有一对多的关系。
@Entity
@Table(name = "complaint_master")
public class ComplaintMaster{
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
@Column(name = "complaint_id")
private long complaint_id;
@OneToMany(mappedBy= "complaintMasterForkey", cascade = CascadeType.ALL )
/*@JsonManagedReference(value="ComplaintTreatmentKey-ComplaintMaster")*/
@LazyCollection(LazyCollectionOption.FALSE)
private List<ComplaintTreatmentKey> complaintTreatmentKey = new ArrayList<>();
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "submitted_on")
private Date submitted_on;
@Column(name = "auth_code")
private String authCode;
// GETTERS AND SETTERS
}
我有另一个表complaints_treatment,其中我必须创建复合主键,但参与的关键两个字段是外键。 所以我用embeded来解决这个问题。
@SuppressWarnings("serial")
@Embeddable
public class ComplaintTreatmentKey implements Serializable {
@ManyToOne(cascade = CascadeType.ALL)
@JsonBackReference(value = "ComplaintTreatmentKey-ComplaintMaster")
@JoinColumn(name = "complaint_id")
protected ComplaintMaster complaintMasterForkey;
@ManyToOne(cascade = CascadeType.ALL)
@JsonBackReference(value = "ComplaintTreatmentKey-ServiceCategory")
protected ServiceCategory serviceCategoryForKey;
}
然后使用@EmbeddedId使用它。
@Entity
@Table(name = "complaint_treatment")
public class ComplaintsTreatment {
@EmbeddedId
private ComplaintTreatmentKey treatmentComplaintKey;
@Column(name = "description")
private String description;
@JoinColumn(name = "status_id")
private StatusMaster statusMaster;
@Column(name = "rca")
private String rca;
@JoinColumn(name = "priority_id")
private PriorityMaster priorityMaster;
@JoinColumn(name = "assigend_to")
private Employee assignedTo;
@Column(name = "closed_on")
private Date closedOn;
}
但通过错误
Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.nxtlife.model.ComplaintMaster.complaintTreatmentKey