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 ?

  • 1
    This is one of the reasons I do not like ORM frameworks.
    – Brandon
    Commented Apr 12, 2014 at 17:29
  • @Brandon The problem is not the ORM the problem is how its being used. Domain objects should not be mapped to a db using an ORM.
    – Andy
    Commented Apr 12, 2014 at 19:58
  • 4
    @Andy: I thought that was kinda the whole point of an ORM. Commented Apr 13, 2014 at 13:55
  • 1
    @RobertHarvey It depends on who you ask. For trivial apps sure, but for more complex apps mapping your business / domain objects directly forces you to design your business / domain objects around the data, and reuse becomes about data, not behavior. I like ORMs, if used correctly, because you have a strongly typed layer to access your data which can easily be code genned. You can then really quickly find out that some column has disappeared by compiling.
    – Andy
    Commented Apr 13, 2014 at 21:57
  • @Andy If you do it like that, then you are using ORM wrong. You should design your mappings based on the domain, not other way around.
    – Euphoric
    Commented Jul 14, 2014 at 5:37

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.