插入顶部链接后无法加载实体

发布于 2024-09-11 14:47:21 字数 506 浏览 4 评论 0原文

我使用 toplink 作为 ORM 工具,我面临一个特殊的问题。我将一个实体插入到会话中,然后在下一行中,如果我尝试加载相同的实体,我无法获取该实体,而是返回 null。但如果我尝试使用休眠,同样的问题,那么它可以正常工作。任何人都可以帮忙吗?

Address address = new Address();
address.setAddressId("1");
address.setPincode(1);
uow2.registerNewObject(address);
ExpressionBuilder builder = new ExpressionBuilder();
Expression expr = builder.get("addressId").equal("1");
Address address1 = (Address)uow2.readObject(Address.class, expr);

最后我得到的地址1为空。我不明白,因为我正在使用相同的密钥插入对象,然后尝试检索它...请帮助我...

i am using toplink as ORM tool, i am facing one peculiar problem. I am inserting an entity into the session and then in the next line if i try to load the same entity, i am unable to get that, instead it returns me null. But the same issue if i try using hibernate, then it works properly. can any one please help.

Address address = new Address();
address.setAddressId("1");
address.setPincode(1);
uow2.registerNewObject(address);
ExpressionBuilder builder = new ExpressionBuilder();
Expression expr = builder.get("addressId").equal("1");
Address address1 = (Address)uow2.readObject(Address.class, expr);

at the end i get address1 as null. i don't understand as i am inserting the object with the same key and then trying to retrieve it... plz help me...

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

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

发布评论

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

评论(1

十二 2024-09-18 14:47:21

这是本机 TopLink/EclipseLink 代码。您只是将地址“注册”到工作单元,在提交之前不会写出。

有几种方法可以从 UnitOfWork 获取未提交的结果。在上面的场景中,您可以在注册新对象之前调用 uow.setShouldNewObjectsBeCached(true) ,然后 readObject 调用将找到它。

您还可以将 readObject 调用更改为 ReadObjectQuery 并在查询上设置 conformResultsInUnitOfWork。

如果您刚刚开始使用 EclipseLink/TopLink,那么我建议使用 JPA API。您将能够在 JPA 上找到许多资源。然后,一旦您开始优化代码或开始处理复杂的场景,您就可以使用 EclipseLink 邮件列表和论坛来获得 EclipseLink 的特定帮助。

This is Native TopLink/EclipseLink code. You are only 'registering' the Address with the UnitOfWork which does not write out until committed.

There are a couple of ways to get uncommitted results from a UnitOfWork. In the scenario above you can call uow.setShouldNewObjectsBeCached(true) before registering the new object then the readObject call will find it.

You can also change the readObject call to a ReadObjectQuery and set conformResultsInUnitOfWork on the query.

If you are just starting out with EclipseLink/TopLink then I recommend using the JPA APIs. You will be able to find many resources on JPA. Then once you begin to optimize your code or begin to tackle complicated scenarios you can use the EclipseLink mailing lists and forums to get EclipseLink specific assistance.

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