jpa删除manytomany链接

发布于 2024-09-11 09:00:26 字数 687 浏览 1 评论 0原文

我有一个事件表,我想将它们分组。 当我想完全删除组时,但当我想更新组以删除一些链接,让事件仍然存在时,这些注释就可以

    // this cascade group still removes the join table but not the products table
@ManyToMany(targetEntity=Product.class,fetch = FetchType.EAGER, cascade = 
   {CascadeType.PERSIST, CascadeType.REFRESH,CascadeType.MERGE})
@JoinTable(name = "lcw_group_product", 
    joinColumns = { @JoinColumn(name = "group_id", referencedColumnName="id") }, 
    inverseJoinColumns = { @JoinColumn(name = "product_id", referencedColumnName="id") })
@ElementForeignKey(updateAction = ForeignKeyAction.CASCADE)
    public Set getProducts() {
        return products;
    }

工作,我找不到方法来做到这一点,我是当前正在执行链接表的删除语句,但这不会反映在父实体中

I have a table of events and i want to make groups of them. that is the easy easy

    // this cascade group still removes the join table but not the products table
@ManyToMany(targetEntity=Product.class,fetch = FetchType.EAGER, cascade = 
   {CascadeType.PERSIST, CascadeType.REFRESH,CascadeType.MERGE})
@JoinTable(name = "lcw_group_product", 
    joinColumns = { @JoinColumn(name = "group_id", referencedColumnName="id") }, 
    inverseJoinColumns = { @JoinColumn(name = "product_id", referencedColumnName="id") })
@ElementForeignKey(updateAction = ForeignKeyAction.CASCADE)
    public Set getProducts() {
        return products;
    }

These annotations work when i want to completely remove the group but when i want to update the group to remove some of the links, leaving the events still there, i can't find a way to do this, i am currently doing delete statements of the link table but this doesn't get reflected in the parent entity

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后来的我们 2024-09-18 09:00:26

只是为了澄清 ElementForeignKey 是一个 OpenJPA 注释,而不是 JPA 注释。
不幸的是,到目前为止,ManyToMany 注释还没有 orphanRemoval 属性。

Just to clarify that the ElementForeignKey is an OpenJPA annotation, not a JPA one.
Unfortunately, so far there is no orphanRemoval attribute for the ManyToMany annotation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文