简体   繁体   English

更新 ElementCollection 时是否会触发包含 object 的 @PostUpdate?

[英]When updating an ElementCollection does it trigger the @PostUpdate of the containing object?

I have an @ElementCollection Map<User, Long> permissions in a class.我在 class 中有一个@ElementCollection Map<User, Long> permissions

    @ElementCollection
    @CollectionTable(name = "als_permission", joinColumns = @JoinColumn(name = "File"))
    @MapKeyJoinColumn(name = "User")
    @Column(name = "Permission")
    @JsonIgnore
    private Map<User, Integer> permissions = new HashMap<>();

I made some changes on that collection only, and invoke repo.save(entity) .我只对该集合进行了一些更改,并调用repo.save(entity) I see the record does get updated, but my @PostUpdate handler which is defined in @EntityListeners does not appear to be called.我看到记录确实得到了更新,但我在@EntityListeners中定义的@PostUpdate处理程序似乎没有被调用。

Is there something I have to put to indicate it?有什么我必须指出的吗? I am thinking I may need to have some sort of cascade somewhere.我在想我可能需要在某个地方进行某种cascade

Short Answer: No.简短的回答:没有。

I had the same issue came to the conclusion that this is not possible at the moment.我有同样的问题得出的结论是目前这是不可能的。 Mainly because intended or not implemented yet, see: https://github.com/eclipse-ee4j/jpa-api/issues/167主要是因为打算或尚未实现,请参阅: https://github.com/eclipse-ee4j/jpa-api/issues/167

For the testing I created a repository to find any event I could consumer for the given purpose: https://github.com/HannesRakete/so-jpa-element-collection-events对于测试,我创建了一个存储库来查找我可以为给定目的使用的任何事件: https://github.com/HannesRakete/so-jpa-element-collection-events

Workaround 1解决方法 1

Add a @Version for optimistic locking on the parent entity.添加 @Version 以对父实体进行乐观锁定。

Workaround 2解决方法 2

Migrate to another association-type, see https://thorben-janssen.com/hibernate-tips-query-elementcollection/迁移到另一种关联类型,请参阅https://thorben-janssen.com/hibernate-tips-query-elementcollection/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 @PreUpdate、@PostUpdate、@PrePersist、@PostPersist、@PreRemove 和 @PostRemove 不适用于带有 OpenXava 的 @ElementCollection 的 @Embeddable - @PreUpdate, @PostUpdate, @PrePersist, @PostPersist, @PreRemove and @PostRemove do not work in an @Embeddable for an @ElementCollection with OpenXava 从@ElementCollection中搜索对象 - Searching An object from @ElementCollection @ElementCollection 是否暗示 orphanRemoval? - Does @ElementCollection imply orphanRemoval? @ElementCollection不会脱离 - @ElementCollection does not getting detached 更新休眠对象的异常,该对象的表具有关联的历史记录触发器 - exception when updating hibernate object whose table has a history trigger tied to it Hibernate + JPA 找不到 @ElementCollection 表的列 - Hibernate + JPA does not find the column for an @ElementCollection table 让我的EventListeners触发@ElementCollection属性的诀窍是什么? - What's the trick to have my EventListeners trigger for my @ElementCollection properties? 在 Play 框架中使用 ElementCollection 时出现 LazyInitializationException - LazyInitializationException when using ElementCollection in Play framework 当映射包含 DTO 列表的对象成功时,为什么映射 DTO 列表失败? - Why does mapping a List of DTOs fail, when mapping an object containing a list of DTOs is successful? 包含JXPanel时,为什么JScrollPane不起作用? - Why JScrollPane does not work when containing a JXPanel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM