I have a general understanding of Hibernate but I'm more interested in cashing capabilities, so I've started from Ch.13. But the following example confused me a little bit:
A proxy is useful if you need the Item only to create a reference, for example:
Code:
Item item = (Item) session.load(Item.class, new Long(123));
User user = (User) session.load(User.class, new Long(1234));
Bid newBid = new Bid("99.99");
newBid.setItem(item);
newBid.setBidder(user);
session.save(newBid);
You first load two objects, an Item and a User. Hibernate doesn’t hit the database
to do this: It returns two proxies. This is all you need, because you only require
the Item and User to create a new Bid. The save(newBid) call executes an INSERT
statement to save the row in the BID table with the foreign key value of an Item
and a User—this is all the proxies can and have to provide. The previous code
snippet doesn’t execute any SELECT!
As far as I understand, session.load is the Hibernate way to retrieve by primary key. If the previous snippet doesn't execute any SELECT, how Hibernate knows that an Item entity with id 123 exists?