首页 > 解决方案 > 引起:java.lang.IllegalStateException:同一实体的多个表示

问题描述

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

应用程序的主要类别:

@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

标签: javajpajoinspring-data-jpa

解决方案


推荐阅读