I have an HQL query that, every time I run it, throws Antlr.Runtime.MismatchedTokenException: 'A recognition error occurred.'
. So far as I can tell, this is because I'm trying to use an entity property called End
, which is a reserved keyword in HQL. Drilling down into the error shows me that when it tries to interpret the token End
, it gives it a token type of 38, whereas all other identifiers in the query have token type 56.
All the solutions I can find for similar problems say that you can fix it by escaping the column name using backticks in the mapping file, and then NHibernate can magically interpret the column name properly. The trouble is, I don't have a column named End
to escape - it's a custom mapped component:
public class EmploymentPeriodMap : EntityAggregateRootMap<EmploymentPeriod>
{
public EmploymentPeriodMap()
{
Map(occupancy => occupancy.PersonId)
.Not.Nullable();
Component(x => x.EmploymentDates, dateRange =>
{
dateRange.Map(x => x.Start, "StartDate")
.Not.Nullable()
.Access.CamelCaseField(Prefix.Underscore);
dateRange.Map(x => x.End, "EndDate")
.Nullable()
.Access.CamelCaseField(Prefix.Underscore);
});
}
}
Because HQL uses the mapped version of entities, I can't just go SELECT employmentPeriod.EndDate
, but going SELECT employmentPeriod.EmploymentDates.End
results in the MismatchedTokenException.
Any idea how I can manage to convince NHibernate to look at the End property, rather than assuming I'm trying to end a case statement I never started?