Quote:
How can I create an association to an entity without fetching that entity from the database (if I know the identifier)?
If the entity is proxyable (lazy="true"), simply use load(). The following code does not result in any SELECT statement:
Item itemProxy = (Item) session.load(Item.class, itemId);
Bid bid = new Bid(user, amount, itemProxy);
session.save(bid);
I just found the above snippet browsing the Hibernate faqs (Tips & Tricks). My question is if it is a good practice if we are working with a domain model. Are we not letting relational artifacts seep into the code, i.e. itemId is a foreign key.