Reputation: 171
I'm trying create one table in my database that need have two foreign key columns. but I have one exception and I don't know how to solve this error:
Could you please help me?
Exception:
No identifier specified for entity: com.xxx.client.db.domain.app.PhoneComp
Follow my Entity Class
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 **/
}
Upvotes: 1
Views: 45
Reputation: 1026
class PhoneComp is missing a field annotated with @Id. Each @Entity needs an @Id - this is the primary key in the database.
If you don't want your entity to be persisted in a separate table, but rather be a part of other entities, you can use @Embeddable instead of @Entity.
Upvotes: 0
Reputation: 828
Your entity PhoneComp
needs to have a primary key annotated by @Id
.
Upvotes: 1