Francois
Francois

Reputation: 2369

Hibernate DAO method parameters

Which one do you prefer and why?

  1. Reservation[] find(User user, Show show)
  2. Reservation[] find(long userId, long showId)

Thanks

Upvotes: 1

Views: 231

Answers (1)

mdma
mdma

Reputation: 57707

If you have a free choice, with no constraints, then I'd always choose the first. In fact, I'd also return a Collection, such as a List rather than an array.

The reason is that using domain objects rather than ids keeps focus on the business side of things, rather than on the relational aspects.

An interface dealing only in domain objects is also easier to mock, since you don't have to suddenly fabricate ids.

Upvotes: 2

Related Questions