title: What is the behavor of pessimistic locking when accessing a belongsTo or other relationship?
body: <p>I'm utilizing <a href="https://gorm.grails.org/6.0.x/hibernate/manual/index.html#_pessimistic_locking" rel="nofollow noreferrer">pessimistic locking</a> in my password reset code.</p>
  
  <p>Basically what happens is the user provides a token (that was emailed to them in a prior transaction), then in a service the state is retrieved with <code>PasswordResetRequest.findByToken(token, [lock: true])</code>. Some validation happens (was the token valid? did the request expire?), and then the user associated with this reset request is retrieved with <code>request.user</code> (a <code>PasswordResetRequest belongsTo User</code> relationship). The user's password is then updated, the user is saved, and the <code>PasswordResetRequest</code> deleted.</p>
  
  <p>I know that according to the docs, the <code>PasswordResetRequest</code> will be locked (and thus a new query will block when retrieving it). But what about the <code>User</code> that's associated with it? What happens if I have some other request happening that reads a user by ID, updates, and saves it (say the user was miraculously updating their account at the same time they were resetting their password)?</p>
  
  <p>So my question is, when locking a child that <code>belongsTo</code> parent, does the parent get locked as well? If not, how would I achieve this (do I need to perform eager fetching or something)?</p>
  
  <p>I'm also curious about the behavior of other relationships. Is there documentation that talks about all of these?</p>