引起:java.lang.IllegalStateException:同一实体的多种表示

时间:2021-06-06 21:26:36

标签: java jpa join spring-data-jpa

我的数据库包含应用程序,每个应用程序都有功能。 每个应用必须至少有一个功能,并且每个功能可以与多个应用相关联。

应用的主要类:

@Entity
@Table(name = ("apps"))
public class AppEntity implements Serializable {

    @Id
    @Column(name = ("app_id"), nullable = false)
    private String appId;

    @Column(name = ("app_name"), nullable = false)
    private String packageName;

    @OneToMany(mappedBy = "appEntity", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    private List<AppFeatureEntity> appFeatures = new ArrayList<>();

特征类别:


@Entity
@Table(name = ("app_features"))
public class AppFeaturesEntity implements Serializable {

    @EmbeddedId
    protected AppFeaturesEntityKey keys;

    @ManyToOne(fetch=FetchType.LAZY,  optional = false)
    @JoinColumn(name = ("app_id"),  insertable = false, updatable = false)
    @JsonIgnore
    private AppEntity appEntity;

PK课:

@Embeddable
public class AppFeaturesEntityKey implements Serializable {

    @Column(name = ("feature_id"), nullable = false)
    private String featureId;

    @Column(name = ("app_id"), nullable = false)
    private String appId;

我正在使用 ModelMapper 根据更新后的实体更新旧实体,当我尝试调用 JpaRepository.saveAll(List<AppEntity>) 时出现错误:

Multiple representations of the same entity [....AppFeaturesEntity#...AppFeaturesEntityKey@32d2bdd] are being merged

0 个答案:

没有答案
相关问题