JDO 的删除顺序是什么
我的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题是因为您在一个事务中删除了 Approver,并在另一个事务中删除了 Request。尝试提交您删除了 Approver 的事务。
您可能想做的第二件事是
ALTER
Request
表定义并使用ON DELETE CASCADE
定义它,然后您不需要完成所有这一切靠你自己。不确定是否有什么东西、某些要求阻止你这样做。I think the problem is because you are deleting the
Approver
s in a transaction, and deletingRequest
in another. Try committing the transaction in which you deleted theApprover
s.Second thing you might want to do is to
ALTER
theRequest
table definition and define it withON 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.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).