I have the following 2 entities:
@Entity(name = "Employee")
@Table(name = "EMPLOYEE")
public class Employee implements Serializable {
@Id
@Column(name = "EMP_ID", insertable = true, updatable = false, nullable = false)
private int id;
以及
@Entity(name = "Draw")
@Table(name = "DRAW")
public class Draw extends AuditableEntity {
@Id
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name = "EMP_ID", referencedColumnName = "EMP_ID")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.MERGE})
private Employee employee = null;
只想说,他们想要模仿它的方式。 这是一种特有的“一对一”关系。 然而,在我接受测试时,我有以下错误:
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name sessionFactory defined in class path resource [META-INF/spring/datasource-context.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: composite-id class must implement Serializable: com.myprojects.tet.data.entity.Draw
Why is the employee
key in Draw
interpreted as a composite-id? Also how do I fix this error. I have read that the entity referenced has to be serializable but also that it needs to implement method equals
以及 hashCode
(which I haven t implemented yet). Should implementation of those two fix that error?
www.un.org/Depts/DGACM/index_spanish.htm 清晰度:
I have two modeled tables: EMPLOYEE
以及 DRAW
:
The draw table will be populated 以及 purged every certain time, so column totalPoint
cannot be in table EMPLOYEE
. I am unsure if my entity relations are correct (i.e. having entity employee
as the id for draw
).