I have an entry class with a many-to-many relationship with a tags class. I'm trying to restore a historical copy of an entry.
I've tried querying like this:
AuditReader reader = AuditReaderFactory.get(getEm());
var entryRevision = reader.createQuery()
.ForEntitiesAtRevision(typeof(IEntry), false, true)
.Add(new IdentifierEqAuditExpression(entryId, true))
.Add(AuditEntity.RevisionNumber().Eq(revisionNumber)))
.GetResultList().SingleOrDefault();
However, on attempting to access the Tags
property or entryRevision
, I get an error:
NHibernate.LazyInitializationException : Initializing[Unavailable#]-failed to lazily initialize a collection, no session or session was closed
I have confirmed that the session is still open when I try to access the tags.
I would like to work around this by querying the Tag_Entry_AUD
table directly to get all the tag ids that might have once been associated with this entry, but I'm not sure how to? Is it possible to do this with an HQL query?