Lock query entity for transaction to prevent FK error while updating search results.