Hibernate设计:持久数据加临时运行时类

发布于 2024-08-25 12:12:32 字数 269 浏览 8 评论 0原文

问题是这样的。 我有许多持久化对象,我将使用 Hibernate 来提取它们。

但在应用程序的生命周期中,我将创建一些对象 不要存在于应用程序的运行时间之外。

它们是临时的,例如包含用户的选择,并且它们还保存 链接到持久对象(表)。但一旦应用程序退出, 它们没有必要,因此临时对象会被销毁。

您认为这些对象是否应该保存在保存普通数据的同一个数据库中?

例如,它们可能保存在临时表中,退出时数据将被删除。

或者它们可能仅在内存中创建。哪个更好?

The question is this.
I have a number of persisted objects that I'll pull using Hibernate.

But during the application lifetime I'll create a few objects that
do not live outside the running time of an app.

They are temporary, for example contain user's choices, and they also hold
links to the persistent objects(tables). But as soon as application exited,
there's no need in them so temporary objects are destroyed.

How do you think, should those objects be persisted in the same database where normal data is kept?

For example, they may be kept in temporary tables and on exit the data will be erased.

Or they may be created only in memory. Which is better?

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

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

发布评论

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

评论(1

↙温凉少女 2024-09-01 12:12:32

通常不会持久化瞬态对象,除非有很多瞬态对象占用内存和/或很少访问这些对象,此时可以更好地使用因不将它们保留在内存中而释放的内存。

在我看来,每个设计的基础都应该是简单。尽可能简单,同时根据需要尽可能复杂。将 Hibernate 添加到这些对象会增加复杂性和潜在的麻烦,如果没有必要,就不要这样做。

You generally don't persist transient objects, unless there are a lot of them gobbling up memory and/or the objects are accessed only rarely, at which point the memory freed by not having them in memory can be used better.

In my opinion, the basis of every design should be simplicity. As simple as possible while as complex as required. Adding Hibernate to those objects adds complexity and potential for trouble, and if it's not necessary then don't do it.

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