I have studied some persistence frameworks mainly Hibernate, DORM, TMS Aurelius and I’m wondering. In a model of type:
TOrderFiscal < > ----- > Items < > -------- > TOrderItem ------- > TProduct
TOrderFiscal --------- > TSuplier --------- > TCidade -------- > State
Each class of this with countless attributes, all mapped correctly to their corresponding tables and fields. When carrying a note without using “Lazy Load” would always be done with several joins select all fields to come from each of these classes.
But it would be a waste since the note need only the supplier code and name attributes, the attributes OrderItem need only code, qty name. stock.
What solution should be taken to create a specific class supplier of note just with these attributes ? eg
TOrder <> ----- > Items <> -------- > TOrderItem ------- > TNotaItemProduct
TOrder -------- > TOrderSupplier
If this is the solution , what happens when a business rule in TProduct should also be TOrderItemProduct? I duplicate code in both classes? Do heritage, eg TORderItemProduct and TProduct both inheriting from TBaseProduct ?
Or is this a concern that we programmers we should not have ?
6
This is what we use the Hibernate Query Language (hql) for – to select only the desired data when the entire object web is not needed. For example:
select new map (s.code as sCode, s.name as sName, i.code as iCode, i.qty as qty, i.name as iName, i.stock as stock)
from TOrderFiscal tof
join tof.suplier s
join tof.items i
join i.product p
where p.id = 12345;
You will get back a list of map of string to object, where each item in the list is a row in the result set represented as a map of the selected field aliases to the field values.