hibernate - Populate the domain model from data layer, or query database direct? -
say have domain model 3 objects interact, reservation, vehicle , fleet. fleet has many vehicles, , each vehicle can have many reservations. e.g.
fleet -1--*- vehicle -1--*- reservation
if want fleet have method getmostpopularvehicle(), have iterate each vehicle , count number of reservations.
if want introduce orm persistence, should (1) have getmostpopularvehicle() call data layer method populate fleet, vehicles , reservations before iterating before? or should (2) query database directly popular vehicle in data layer method?
my thinking (1) correct, database query can efficient. perhaps approaching wrong?
both approaches valid. depends on want achieve; if can performance issueing (hql or jpql or whatever orm supports) query, uses domain model well, quite legal this.
Comments
Post a Comment