将 JFace 数据绑定与 Hibernate 结合使用:这可能吗?

发布于 2024-09-28 14:58:03 字数 385 浏览 0 评论 0原文

我们的项目是一个使用 Hibernate 作为 ORM 的 Eclipse RCP 应用程序。我最近了解了 JFace 数据绑定,其中 GUI 和数据模型可以自动同步。

我按照 Lars Vogel 优秀的 JFace 数据绑定教程 并且对该框架印象深刻。

那么,有什么方法可以将其挂接到 Hibernate 中,以便在观察到的小部件中所做的更改自动保留在数据库中吗?这似乎是很自然的事情,但我没有找到好的教程。

我怀疑我可能找错了方向,或者错过了一些基本概念。

有人尝试这样做吗?这里的“最佳实践”是什么?

Our project is an Eclipse RCP application using Hibernate as an ORM. I recently learned about JFace databinding, in which the GUI and data models can be synchronized automagically.

I put together a short test implementation along the lines of Lars Vogel's excellent JFace Data Binding Tutorial and was fairly impressed with the framework.

Is there any way, then, to hook this into Hibernate, such that changes made in an observed widget are automatically persisted in the database? This seems like a natural thing to want to do, and yet I've found no good tutorials.

I suspect that I may be barking up the wrong tree, or have missed some fundamental concept.

Has anyone tried to do this? What's the "best practice" here?

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

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

发布评论

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

评论(1

不必在意 2024-10-05 14:58:03

我认为您不应该在每次修改 GUI 后将数据模型保存到数据库中。一些原因:

  • 它可能会导致非常糟糕性能(最坏的情况是在每次按键后调用数据库更新)
  • 可能很难实现某些 GUI 行为(例如,您的用户可以“取消”编辑操作吗? ?如何“恢复”原始值?)

如果您的申请表包含某种“应用”/“保存”等内容。按钮和取消按钮 您有一些明确定义的点,您需要在其中执行数据库操作:

  • 使用数据绑定来连接数据模型和 GUI
  • 应用或保存按钮处理程序将编辑的实体保留在数据库中
  • 取消按钮处理程序可以重新加载如有必要,从数据库中编辑实体(放弃编辑)

只是我的两分钱...

免责声明:我在上面使用了非常简单的示例来说明我的想法。例如,您永远不应该直接从 GUI 调用数据库/Hibernate 操作(在 GUI 和数据库之间使用“中间层”以确保模块化和可测试性)。

I do not think you should persist your data model to a database after every modification in the GUI. Some reasons:

  • it could lead to really bad performance (the worst case is calling a database update after every keystoke)
  • it could be hard to implement some GUI behaviour (e.g. can your user 'cancel' an edit operation? How do you 'restore' the original values?)

If your application form contains some kind of an Apply/Save/etc. button and a Cancel button you have some well defined points where you need to do database operations:

  • use data binding to connect your data model and the GUI
  • an Apply or Save button handler persists the edited entity in the database
  • a Cancel button handler could reload the edited entity from the database if necessary (discarding the edits)

Just my two cents...

Disclaimer: I used very simple examples above to illustrate my thoughts. E.g. you should never call database/Hibernate operations directly from the GUI (use a 'middle tier' between the GUI and the database to ensure modularity and testability).

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