For anyone who's ever done something like the following...
Code:
session.refresh(customer, LockMode.UPGRADE);
customer.getAccount().setBalance(100);
session.saveOrUpdate(customer);
The above can result in your application updating stale data, because refresh() retrieves the account before the customer, i.e.
Code:
select account.id, account.balance where account.id=$1 from account;
select customer.id, customer.name from customer where customer.id=$1 for update;
So at the point where the account is retrieved your application hasn't obtained an exclusive lock and the data may therefore be stale. Locking the parent entity to update a child isn't something you're likely to do on a daily basis but occasionally it's useful (e.g. if you've already obtained a lock on the parent earlier in the call stack). Anyway, the above is definitely not the way to do it!