相关疑难解决方法(0)

已删除的对象将通过级联重新保存(从关联中删除已删除的对象)

我有以下两个实体:

1-播放列表:

@OneToMany(fetch = FetchType.EAGER, mappedBy = "playlist", orphanRemoval = true, cascade =   CascadeType.ALL)
@OrderBy("adOrder")
private Set<PlaylistadMap> PlaylistadMaps = new HashSet<PlaylistadMap>(0);
Run Code Online (Sandbox Code Playgroud)
  • CascadeType.ALL:在保存或更新播放列表实体时,需要在PlaylistadMap集合上进行保存和更新.
  • 删除播放列表实体时需要使用orphanRemoval = true:还应删除PlaylistadMap引用.

2- PlaylistadMap:

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "fk_playlist", referencedColumnName = "pkid", nullable = false)
private Playlist playlist;
Run Code Online (Sandbox Code Playgroud)

使用getCurrentSession().delete();我删除播放列表时,我收到以下异常:

org.springframework.dao.InvalidDataAccessApiUsageException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.xeno.advertisingsuite.web.domain.PlaylistadMap#6]; nested exception is org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): …
Run Code Online (Sandbox Code Playgroud)

hibernate jpa one-to-many java-ee

46
推荐指数
3
解决办法
9万
查看次数

从@ OneToMany-association中删除子项:CascadeType.ALL + orphanRemoval = true not working

我很难从OneToMany协会中删除孩子.我的实体:

@Entity
@Table(name = "PERSON")
public class PersonEntity extends BaseVersionEntity<Long> implements Comparable<PersonEntity>
{
  ...
  // bi-directional many-to-one association to Project
  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "person", orphanRemoval = true)
  private final Set<ProjectEntity> projects = new HashSet<ProjectEntity>();
  ...

@Entity
@Table(name = "PROJECT")
public class ProjectEntity extends BaseVersionEntity<ProjectPK>
{
  @EmbeddedId
  private ProjectPK id;
  ...
  // bi-directional many-to-one association to UdbPerson
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "PERSON_ID", nullable = false, insertable = false, updatable = false)
  private PersonEntity person;
  ... …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa-2.0

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

hibernate ×2

java ×1

java-ee ×1

jpa ×1

jpa-2.0 ×1

one-to-many ×1