views:

54

answers:

1

Hi,

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...

+1  A: 

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.

haarrrgh
Wouldn't that be style #2: Domain Model? What happens to performance in such a case? Does Hibernate automatically do some 'magic' inside... that addresses any performance issues? Sorry for my ignorance about Hibernate: I'm just asking this very high-level question so that before I invest many weeks trying to learn Hibernate, I don't discover that it is not performant enough, or that you must sacrifice OO "purity" / "elegance" in your domain model.
Harry
I edited my answer, see above!
haarrrgh