@Entity()
export class Job {
@PrimaryKey({ type: BigIntType })
id: string;
@OneToMany(() => JobExperienceLevel,
jobExperienceLevel => jobExperienceLevel.job, {cascade: Cascade.ALL], orphanRemoval: true})
experienceLevels = new Collection<JobExperienceLevel>(this);
}
@Entity()
export class JobExperienceLevel {
@PrimaryKey()
@Enum({
items: () => JobExperienceLevelType
})
experienceLevel: JobExperienceLevelType;
@ManyToOne({nullable:false, primary: true, joinColumn: 'job_id'})
job: Job;
}
export enum JobExperienceLevelType {
ENTRY_LEVEL = 'ENTRY_LEVEL',
JUNIOR = 'JUNIOR',
REGULAR = 'REGULAR',
SENIOR = 'SENIOR'
}
在某个作业实体上调用 experienceLevels.removeAll() 后,它会生成以下查询:
delete from `job_experience_level` where `experience_level` = 'SENIOR' and `job_id` is null
数据库表“job_experience_level”仅包含复合主键(experience_level、job_id)
我已经检查过在调用 removeAll 方法之前集合中有一个实体“高级”。
我在作业实体上使用带有 persistAndFlush 的 entityrepository。
问题是这个查询是错误的,它应该填充正确的job_id。
我还尝试从 experienceLevel 属性中删除 @PrimaryKey() ,但是事务中根本没有删除查询。