JDO 的删除顺序是什么

发布于 2024-08-24 20:54:29 字数 292 浏览 5 评论 0原文

我的oracle数据库中有两个表

Request和Approver。每个审批者都有一个请求。受约束保护的外键。

在我使用 kodo jdo 3.4 的 java 代码中,我对部分或全部批准者调用删除持久性。 最后,如果没有留下批准者,我会调用请求上的持久删除。当我提交时,我的完整性约束会被触发,因为我猜 sql 运行的顺序是错误的。

有没有办法强制以某种方式对数据库进行删除调用?

我还考虑在所有内容都被删除的情况下自己回滚事务,并以正确的顺序手动强制删除。但这似乎是一种黑客行为。

谢谢

I have two tables in my oracle database

Request and Approver. Every approver has a request. A foreign key protected by a constraint.

In my java code using kodo jdo 3.4 I call delete persistant on some or all of the approvers.
Then at the end if no approvers are left I call delete persistant on the Request. When I commit I my integrity constraint fires because the sql is running in the wrong order I guess.

Is there a way to force the delete calls to the db to happen in a certain way?

I was also thinking of rolling back the transaction myself in the case where everything gets deleted and hand forcing the deletes in the correct order. But that seems like a hack.

Thanks

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

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

发布评论

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

评论(2

烧了回忆取暖 2024-08-31 20:54:29

我认为问题是因为您在一个事务中删除了 Approver,并在另一个事务中删除了 Request。尝试提交您删除了 Approver 的事务。

您可能想做的第二件事是ALTER Request表定义并使用ON DELETE CASCADE定义它,然后您不需要完成所有这一切靠你自己。不确定是否有什么东西、某些要求阻止你这样做。

I think the problem is because you are deleting the Approvers in a transaction, and deleting Request in another. Try committing the transaction in which you deleted the Approvers.

Second thing you might want to do is to ALTER the Requesttable definition and define it with ON DELETE CASCADE, then you need not do it all by yourself. Not sure if there something, some requirement, is stopping you from doing in this way.

眼泪都笑了 2024-08-31 20:54:29

JDO 是否管理关系(例如,Request 是否有 Set 字段并指定 JDO“mapped-by”属性),或者您是否显式设置外键?如果 JDO 知道这种关系,它应该以正确的顺序执行删除。

或者,如果无法更改 JDO 配置,您可以尝试在删除 Approvers 后调用 PersistenceManager 的 flash() 方法。这应该将任何未完成的删除应用于数据存储(尽管仍在事务内)。

Is JDO managing the relationship (for example, does Request have a Set field and specify the JDO "mapped-by" attribute), or are you setting the foreign key explicitly? If JDO is aware of the relationship, it should do the deletes in the right order.

Alternatively, if changing the JDO configuration is not an option, you could try calling the PersistenceManager's flush() method after deleting the Approvers. That should apply any outstanding deletes to the datastore (still within the transaction though).

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