2
votes

Trying HQL, total NHibernate n00b.

public IEnumerable<Log> GetLast(int numRecords, string severity)
{
    var query = _Session.CreateQuery(
        "from Log as l inner join fetch l.UserProfile order by l.TimeStamp desc where l.Severity in (:severities)")
        .SetParameterList("severities", Translator.SeverityOrHigher(severity))
        .SetMaxResults(numRecords)
        .Enumerable<Log>();

    return query;
}

Translator.SeverityOrHigher returns an IList<string>.

I have a Log object which references a UserProfiles object in many-to-one fashion. The objects are persisted in the database as Logs and UserProfiles, respectively.

I am getting the following exception thrown on the var query = ... line:

Exception of type 'Antlr.Runtime.MismatchedTokenException' was thrown.

I have no idea what that even means, and a Google search wasn't especially helpful. I don't know if there's a problem with the HQL, or the way I set this up. Any guidance would be appreciated.

1
It is a list and it is not empty.Jeremy Holovacs

1 Answers

2
votes

I haven't used NHib for ages... have you tried to put the order by statement at the end? Probably it's working like this, by I always put at the end.