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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -