[db] Fix for SQL syntax issues around lastAccessedAt
[message] Use attached instance lookup to prevent select queries inside existing db transaction