春季靴:2.0.2

休眠核心:5.2.17

的方言:SQLServer2012Dialect

尝试使用JpaRepository save()方法保存DistributionActivities实体时,操作失败,并显示以下消息:


  org.hibernate.id.IdentifierGenerationException:空ID生成
  用于:类DistributionActivitiesEmails


上级实体:

@Entity
@Table(name = "DistributionActivities")
public class DistributionActivities implements Serializable
{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name ="ActivityID")
    private Long activityID;

    @OneToMany(cascade={CascadeType.ALL})
    @Fetch(FetchMode.JOIN)
    @JoinColumn(name="activityID", referencedColumnName="activityID")
    private Set<DistributionActivitiesEmails> distributionActivitiesEmails;
}


子实体:

@Entity
@Table(name = "DistributionActivitiesEmails ")
public class DistributionActivitiesEmails implements Serializable
{
    @EmbeddedId
    private DistributionActivitiesEmailsId id;

    @Length(max = 50)
    private String EmailAdress;
}


复合PK:

@Embeddable
public class DistributionActivitiesEmailsId implements Serializable
{
    @ManyToOne
    @JoinColumn(name="ActivityID")
    private DistributionActivities distributionActivities;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name ="ActivityEmailID")
    private Long activityEmailID;
}

最佳答案

根据@EmbeddedId javadoc,不支持在嵌入式id类中定义的关系映射。

09-25 20:21