Sometimes an entity contains a property that is not directly mapped to a column, but instead holds some value fetched from another (joined) table or a value generated by query. For example, such property can holds some count or the result of some math operation, or value from other table.
We will use example where property SentMessage.content should be populated with value of Message.ctx. Here is the T-SQL query that joins two tables and selects everything what is needed:
select $C{sm.*}, $C{msg.ctx} from $T{SentMessage sm} join ($T{Message msg}) on ($msg.id=$sm.refId) where ...
Since msg.ctx is not part of SentMessage, we can only call
DbOomQuery#list(SentMessage.class, String.class) to receive data.
But, this is painful! The returned result is List<Object[]>, and in order to populate each SentMessage.content we would need to:
List<SentMessage>.Not only that it is un-necessary complicated, but also during this process some additional memory is allocated to hold both lists in the same time.
Fortunately, DbOom framework comes with hints;) As explained elsewhere, they can be used in situations like this, where we can instruct how returned values can injected one into another.
So what would be the hint in our example? Its easy: for each row, please inject msg.ctx into sm.content. In the other words, we can say the following: map the first rowset results into sm (SentMessage) and the last rowset result put into sm.content.
Here is how above hint is written in Java:
DbOomQuery q = query(sql("select $C{sm.*}, $C{msg.ctx} as content from $T{SentMessage sm} join ($T{Message msg}) on ($msg.id=$sm.refId) where..."));
// set parameters
List<SentMessage> list = q.withHints("sm, sm.content").listAndClose(SentMessage.class, String.class);
And that is all! Also note that returned value is List<SentMessage>, so everything is just ready.