Spring DATA JPA: How to get success/failures while database constraint (Unique key violation) on saving a nested entity

huangapple 未分类评论44阅读模式
英文:

Spring DATA JPA: How to get success/failures while database constraint (Unique key violation) on saving a nested entity

问题

我想在特定情况下保存具有“一对多”关系的实体,其中嵌套实体引发唯一约束异常,而不回滚事务。

我希望保存嵌套实体仍然是唯一的,并且对于重复实体会得到异常。

示例:实体A具有包含X个重复记录的实体B类型的列表/集合。在将其持久化到数据库中时,如果数据库中已经存在记录,我想知道从列表/集合中未能持久化的哪个记录,并且记录能够成功持久化。

以下是与同一问题相关的一些参考:

英文:

I want to save an entity having one to many relationship in specific case where the nested entity throws unique constraint exception without rolling back the transaction.

I want to save the nested entity which is still unique and get an exception for duplicate entity.

Example: Entity A has list/set of entity B type containing X amount of duplicate records. While persisting in the database if the record exists already in database I want to know which record failed to persist from the list/set and the records to be successfully persisted.

Below are some reference for the same problem but no concrete solution.

- [https://stackoverflow.com/questions/32691128][1]
- [https://stackoverflow.com/questions/15731297][1]
- [https://stackoverflow.com/questions/3502279][1]
- [https://stackoverflow.com/questions/54343137][1]

huangapple
  • 本文由 发表于 2020年4月9日 18:14:24
  • 转载请务必保留本文链接:https://java.coder-hub.com/61118848.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定