-1
我有這個層次當我把多對一註釋
T1(
id (pk),
name (varchar)
)
T2(
id (pk),
t1_id (fk_t1),
number (int)
)
T3 (
id (pk),
t2_id (fk_t2),
time (datetime)
zone (tinyint),
name (varchar)
)
,這是我T3Entity
@Entity
@Table(name="T3, schema="", catalog="dbname")
public class T3Entity{
private int id;
private DateTime datetime;
private int zone;
private String name;
@Id
@Column(name="id", nullable=false, insertable=true, updatable=true)
//GETTER/SETTERS
@Basic
@Column(name="datetime", nullable=false, insertable=true, updatable=true)
//GETTER/SETTERS
@Basic
@Column(name="zone", nullable=false, insertable=true, updatable=true)
//GETTER/SETTERS
@Basic
@Column(name="name", nullable=false, insertable=true, updatable=true)
//GETTER/SETTERS
}
當我T3Entity
類添加該代碼沒有主鍵的錯誤,我得到了一個錯誤
@ManyToOne(fetch=FetchType.Lazy)
@JoinColumn(name="T2_id", referencedColumn="T2_id")
private T2Entity t2Entity;
//getters-setters
我得到這個錯誤
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [PU] failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class com.project.entity.T3Entity] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.