关于 Hibernate 的新手问题......在 Martin Fowler 文章的背景下

发布于 2024-09-15 09:29:51 字数 370 浏览 3 评论 0原文

域逻辑和 SQL 中,Martin Fowler 讨论了与数据库交互的 3 种风格:

  1. 事务脚本
  2. SQL 中的领域模型和
  3. 逻辑

我想知道的是:

  1. 当使用 Hibernate 进行持久化时,通常使用和/或鼓励使用上述 3 种风格中的哪一种?
  2. 使用Hibernate时有第四种风格吗?

(在 Hibernate 环境中,用 HQL 代替上面的 SQL。)

非常感谢...

In Domain Logic and SQL, Martin Fowler talks about 3 styles of interfacing with a database:

  1. Transaction Script
  2. Domain Model, and
  3. Logic in SQL

What I'd like to know is:

  1. When employing Hibernate for persistence, which of the above 3 styles is typically used and/or encouraged?
  2. Is there any 4th style when using Hibernate?

(In context of Hibernate, substitute HQL in place of SQL above.)

Many thanks...

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

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

发布评论

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

评论(1

你如我软肋 2024-09-22 09:29:51

通常,您将 O/R 映射器(例如 Hibernate)与域模型一起使用。


编辑:

是的,那就是#2,领域模型。
实际上,我对Hibernate了解不多,我只使用NHibernate(Hibernate的.net端口)。但由于它是 Hibernate 的一个端口,所以基础知识应该大致相同。
Hibernate 和 NHibernate 可能会使用内部巫术来提高性能,但我对它们的内部结构了解不够,无法详细说明。

您还应该考虑到 Fowler 文章的最后更新时间是 2003 年 2 月(7.5 年前!),从那时起,像 (N)Hibernate 这样成熟的 O/R 映射器可能已经提高了性能。

Usually, you use O/R mappers like Hibernate with a domain model.


EDIT:

Yes, that would be #2, Domain Model.
Actually, I don't know much about Hibernate, I only work with NHibernate (the .net port of Hibernate). But as it's a port of Hibernate, the basics should be about the same.
Hibernate and NHibernate probably do their share of internal voodoo to increase performance, but I don't know enough about their internals to elaborate on details.

You should also take into consideration that the Fowler article was last updated in February 2003 (7.5 years ago!), and that mature O/R mappers like (N)Hibernate probably have increased their performance since then.

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