Hey tonyXXX, just wanted to let you know, I found this in the FAQ (
Tips and Tricks):
---------------------
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:
Code:
Item itemProxy = (Item) session.load(Item.class, itemId);
Bid bid = new Bid(user, amount, itemProxy);
session.save(bid);
How can I retrieve the identifier of an associated object, without fetching the association?Just do it! The following code does not result in any SELECT statement, even if the item association is lazy.
Code:
Long itemId = bid.getItem().getId();
---------------------
So by the sounds of things, just going ahead and encapsulating the entities is the way to go. Just be careful of entity.getTarget().getId() when the foreign key can be null.