October 2006
Intermediate to advanced
880 pages
22h 11m
English
You may wish to execute a query against all elements of a collection. For instance, you may have an Item and wish to retrieve all bids for that particular item, ordered by the time that the bid was created. You can map a sorted or ordered collection for that purpose, but there is an easier choice. You can write a query, and you should already know how:
session.createQuery("from Bid b where b.item = :givenItem" +
" order by b.created asc")
.setEntity("givenItem", item);
This query works because the association between bids and items is bidirectional and each Bid knows its Item. There is no join in this query; b.item refers to the ITEM_ID column in the BID table, and you set the value for the comparison directly. ...
Read now
Unlock full access