In Domain Logic and SQL, Martin Fowler talks about 3 styles of interfacing with a database:
- Transaction Script
- Domain Model, and
- Logic in SQL
What I'd like to know is:
- When employing Hibernate for persistence, which of the above 3 styles is typically used and/or encouraged?
- Is there any 4th style when using开发者_运维知识库 Hibernate?
(In context of Hibernate, substitute HQL in place of SQL above.)
Many thanks...
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.
精彩评论