我正在尝试在数据库中创建一个表,该表需要具有两个外键列。 但我有一个例外,我不知道如何解决此错误:
能请你帮我吗?
例外:
未为实体指定标识符:com.xxx.client.db.domain.app.PhoneComp
关注我的实体类
PhoneComp.class
/**
*
* @author joh
*/
@Entity
@Table(name = "phoneComp")
public class PhoneComp implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@JoinColumn(name = "cellPhoneRef", referencedColumnName = "id")
@ManyToOne
private Cellphone cellPhoneReference;
@JoinColumn(name = "cellPhoneComp", referencedColumnName = "id")
@ManyToOne
private Cellphone cellPhoneComp;
public PhoneComp() {}
/**get and sets*/
}
CellPhone.class
/**
*
* @author joh
*/
@Entity
@Table(name = "cellphone")
public class Cellphone implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Column(name = "cellphoneName")
private String cellphoneName;
@Basic(optional = false)
@Column(name = "isActive")
private boolean isActive;
@Column(name = "cellphoneBrand")
private String cellphoneBrand;
@Column(name = "lastModifiedDate")
private Date lastModifiedDate;
public Cellphone() {}
/**get and sets **/
}
答案 0 :(得分:1)
您的实体PhoneComp
需要具有由@Id
注释的主键。
答案 1 :(得分:0)
PhoneComp类缺少用@Id注释的字段。每个@Entity都需要一个@Id-这是数据库中的主键。
如果您不希望您的实体保留在单独的表中,而是希望成为其他实体的一部分,则可以使用@Embeddable而不是@Entity。