我有两个实体,当子实体正在删除时,我想从父集合中删除子实体。delete函数删除子实体,但不从parentchild表中删除记录。
所以我有以下问题:
2021-01-04 11:31:35.601 ERROR 14264 --- [ XNIO-1 task-2] c.f.timesheet.web.rest.AppUserResource : Exception in getAppUser() with cause = 'javax.persistence.EntityNotFoundException: Unable to find com.freemind.timesheet.domain.Job with id 3351' and exception = 'Unable to find com.freemind.timesheet.domain.Job with id 3351; nested exception is javax.persistence.EntityNotFoundException: Unable to find com.freemind.timesheet.domain.Job with id 3351'
我还有一个:
2021-01-04 11:31:35.598 WARN 14264 --- [ XNIO-1 task-2] o.h.e.loading.internal.LoadContexts : HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@55a124f7<rs=HikariProxyResultSet@372007568 wrapping org.postgresql.jdbc.PgResultSet@3901bf09>
实体:
工作(孩子):
@ManyToMany(mappedBy = "jobs", cascade = CascadeType.REFRESH,fetch = FetchType.LAZY)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@JsonIgnore
private Set<AppUser> appUsers = new HashSet<>();
...
public void removeAppUsers() {
if (this.appUsers.size() > 0)
for (AppUser ap : this.appUsers) {
log.debug("Request to delete Job from User : {}", ap);
ap.removeJob(this);
log.debug("Request to delete Job from User : {}", ap);
}
}
应用程序用户(父级):
@ManyToMany(cascade = CascadeType.REFRESH,fetch = FetchType.LAZY)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@JoinTable(
name = "app_user_job",
joinColumns = @JoinColumn(name = "internal_user_id"),
inverseJoinColumns = @JoinColumn(name = "job_id", referencedColumnName = "id")
)
private Set<Job> jobs = new HashSet<>();
...
public AppUser removeJob(Job job) {
this.jobs.remove(job);
job.getAppUsers().remove(this);
return this;
}
服务(@service,@transactionnal):
public void delete(Long id) {
log.debug("Request to delete Job : {}", id);
Job j=jobRepository.getOne(id);
j.removeAppUsers();
jobRepository.deleteById(id);
}
我做错什么了?谢谢您
1条答案
按热度按时间ifsvaxew1#
我用下面的代码测试了这个。问题似乎是您没有保存appuser示例。
appuser类
appuser回购
工作等级
工作回购
测验