Datanucleus JPA 更新 &删除操作
我使用 Datanucleus 作为 JPA 引擎对 Force.com DB 中的实体执行 CRUD。插入和选择工作正常,但在更新时创建新行,而删除根本不会删除记录。我正在使用以下方法执行交易
在获取、修改对象并进行更新后,代理对象与实际对象同步是否存在问题?
似乎由于 ORM 层(datanucleus+force sdk)无法在更改的对象和原始对象之间进行匹配,因此它正在创建新行。
非常感谢任何帮助。
谢谢
I am using Datanucleus as the JPA engine to perform CRUD on an entity in Force.com DB. Insert and Select are working fine, but while updating a new row is getting created and delete does not remove the record at all. I am using following for transaction enforcement
Is there kind of an issue with the proxy object to actual object synchronization after the object has been fetched, modified and then subject to updating.
It seems that as the ORM layer (datanucleus+force sdk) is unable to match between the altered object and the original one, it is landing up creating new row.
Any help is highly appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您可以发布您的代码,将会有所帮助。但我猜测您可能会遇到 DataNucleus 和 Hibernate 等其他 ORM 之间已知的行为差异。
你在做这样的事情吗?
(其中实例化和设置器可能由数据绑定机制(例如 Spring MVC)执行)。如果您这样做,它将不能与DataNucleus一起工作,但它可以与Hibernate一起工作。对于 DataNucleus,您必须这样做:
我希望它像 Hibernate 一样工作,但 DataNucleus 团队认为这是正确的行为。也许他们可以插话。我相信这取决于你何时将一个实体视为新实体与独立实体。如果您的实体实例已分离,则对其调用合并应该重新附加它,并且您的数据库行将在事务提交/刷新时更新。如果它是一个新实例,那么实体管理器将始终创建一条新记录。
至于你的删除问题,我不知道是什么原因。也许您可以发布代码示例?您可以在此处找到使用 JPA 提供程序的完整 CRUD 示例应用程序:
https://github.com/forcedotcom/javasample -musiclib
It would help if you can post your code. But I am guessing you might be hitting a known difference in behavior between DataNucleus and other ORMs like Hibernate.
Are you doing something like this?
(where the instantiation and setters might be carried out by a data binding mechanism such as Spring MVC). If you do it like this, it will not work with DataNucleus but it will work with Hibernate. For DataNucleus you must instead do:
I would prefer it worked like Hibernate, but the DataNucleus team believes this is the correct behavior. Maybe they can chime in. I believe it's a matter of when you consider an entity a new entity vs. a detached entity. If your entity instance is detached, then calling merge on it should reattach it and your database row will be updated at transaction commit / flush. If it's a new instance, then the entity manager will always create a new record.
As for your delete issue, I don't know what it could be. Perhaps you can post a code sample? You can find a complete CRUD sample app using the JPA provider here:
https://github.com/forcedotcom/javasample-musiclib