我想制作一张桌子,假设桌子的名字是Car。它将有3列,brandId,typeId和sizeId。我希望所有列都是主键。 typeId和sizeId是来自不同表的列。我已经尝试使用@IdClass创建代码。但是,出现错误“找不到超类型”。
这是Entity clas:
@Entity
@IdClass(CarPk.class)
@Table(name = "CAR")
public class Car implements Serializable {
private static final long serialVersionUID = -1576946068763487642L;
public Car() {
}
public Car(String brandId, TypeId typeId, SizeId sizeId) {
this.brandId = brandId;
this.typeId = typeId;
this.sizeId = sizeId;
}
@Id
@Column(name = "BRAND_ID", nullable = false, length = 20)
private String brandId;
@Id
@ManyToOne
@JoinColumn(name = "TYPE_ID", nullable = false)
private TypeId typeId;
@Id
@ManyToOne
@JoinColumn(name = "SIZE_ID", nullable = false)
private SizeId sizeId;
public String getBrandId() {
return brandId;
}
public void setBrandId(String brandId) {
this.brandId= brandId;
}
public TypeId getTypeId() {
return typeId;
}
public void setTypeId (TypeId typeId) {
this.typeId= typeId;
}
public SizeId getSizeId() {
return sizeId;
}
public void setSizeId (SizeId sizeId) {
this.sizeId= sizeId;
}
}
这是CarPk课程:
public class CarPk implements Serializable {
private static final long serialVersionUID = -1576946068763487642L;
public CarPk() {
}
public CarPk(String brandId, TypeId typeId, SizeId sizeId) {
this.brandId = brandId;
this.typeId = typeId;
this.sizeId = sizeId;
}
private String brandId;
private TypeId typeId;
private SizeId sizeId;
public String getBrandId() {
return brandId;
}
public void setBrandId(String brandId) {
this.brandId= brandId;
}
public TypeId getTypeId() {
return typeId;
}
public void setTypeId (TypeId typeId) {
this.typeId= typeId;
}
public SizeId getSizeId() {
return sizeId;
}
public void setSizeId (SizeId sizeId) {
this.sizeId= sizeId;
}
}
这段代码有什么问题? 无论如何,谢谢你