springjpa:尝试删除具有外键约束的表中的记录

yftpprvb  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(307)

在使用springboot和springjpa的项目中,一个eninity functionconfiguration,其中包含一个整数目标设备列表

  1. @Entity
  2. @Table(name = "function_configuration")
  3. public class FunctionConfigurationEntity {
  4. @Id
  5. @Column(name = "id_function_configuration")
  6. @GeneratedValue(strategy = IDENTITY)
  7. private Integer idFunctionConfiguration;
  8. @ElementCollection
  9. @CollectionTable(name = "target_device")
  10. private List<Integer> targetDevice;
  11. }

如果我尝试用functionconfiguration的id进行删除

  1. @Transactional
  2. @Modifying
  3. @Query(value = "DELETE FROM FunctionConfigurationEntity fce WHERE fce.idFunctionConfiguration = idFunctionConfiguration")
  4. void deleteByFunctionConfigurationId(@Param("idFunctionConfiguration") Integer functionConfigurationId);

我得到以下错误:

  1. Caused by: org.postgresql.util.PSQLException: ERROR: UPDATE or DELETE statement on table "function_configuration" violates foreign key constraint "fk69tox326tcrs3wed1neufb0pv" on table "target_device"

我该怎么修?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题