我有两张桌子 T1 和 T2。T1 具有 id(PK)、名称、类型。T2 有 SID、TID、Type。T2 的主键是所有 3 的组合:SID、TID、类型。现在 SID 和 TID 是外键,也映射到 T1 的 ID。有人请帮助如何在 JPA 中进行此操作。
package com.sap.table;
import java.io.Serializable;
import java.lang.String;
import javax.persistence.*;
import static javax.persistence.GenerationType.TABLE;
import static javax.persistence.GenerationType.IDENTITY;
/**
* Entity implementation class for Entity: Relations
*
*/
@IdClass(RelationsPK.class)
@Entity
@Table (name = "demo_relations11")
public class Relations implements Serializable {
//@EmbeddedId
//@JoinColumn(referencedColumnName="AssetID")
//private RelationsPK Relations_PK;
// @Id
//// @JoinColumn(referencedColumnName="AssetID")
// private String TargetID;
@Id
private String Type;
private static final long serialVersionUID = 1L;
// @MapsId("SourceID")
@Id
@ManyToOne(targetEntity=Asset.class)
@JoinColumns({
@JoinColumn(name="SourceID", referencedColumnName="AssetID"),
@JoinColumn(name="TargetID", referencedColumnName="AssetID")
})
//@JoinColumn(referencedColumnName="AssetID")
Asset asset;
public Asset getAsset() {
return asset;
}
public void setAsset(Asset asset) {
this.asset = asset;
}
public Relations() {
super();
}
// public String getSourceID() {
// return this.SourceID;
// }
//
// public void setSourceID(String SourceID) {
// this.SourceID = SourceID;
// }
// public String getTargetID() {
// return this.TargetID;
// }
//
// public void setTargetID(String TargetID) {
// this.TargetID = TargetID;
// }
public String getType() {
return this.Type;
}
public void setType(String Type) {
this.Type = Type;
}
}
T1 - ID(PK), 名称, 类型 T2 - SID (FK to ID), TID (FK to ID), Type PK of T2 - SID,TID,Type