JpaSystemException:此类的ID必须在调用save()之前手动分配

时间:2019-07-12 11:00:36

标签: hibernate spring-boot jpa

我正处于例外之下

org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save()

我有两个具有一对多关系的实体(A和B)。从A到B有一对多的关系。两者都有相同的主键列,即key。当我在设置A中的所有属性以及作为实体B列表的映射属性之后保存实体A时,我已经提到了实体A的生成值也为@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "A_SEQ")@Sequence Generator

@Entity
@Table(name = "A")
@SequenceGenerator(name = "A", sequenceName = "A_SEQ", allocationSize = 1)
public class A implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "A_SEQ")
    @Column(name = "key")
    private Integer key;

    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = "key")
    private List < B > b;
}

@Entity
@Table(name = "B")
@PrimaryKeyJoinColumn(name = "key")
public class B implements Serializable {
    @Id
    @Column(name = "key")
    private Integer key;
    .
    .
    .
}

请让我知道我在哪里犯错,并帮助我解决此问题。预先感谢。

0 个答案:

没有答案