English 中文(简体)
A. 实体作为恢复“Composite-ID”错误的“一对一”关系的关键
原标题:Entity as key on a One to One relationship returning "Composite-ID" error

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).

最佳回答

rel=“nofollow”>@PrimaryKeyJoinColumn ::

@Id
@Column(name = "EMP_ID")
private int id;

@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@PrimaryKeyJoinColumn(name = "EMP_ID", referencedColumnName = "EMP_ID")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.MERGE})
private Employee employee;
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签