Hello-
I have a column named "End" in a table of mine that holds sessions. Since "End" is a reserved word in SQL Server 2005, I'm getting the following error when I use some HQL to query for a session where the "End" column is null:
Incorrect syntax near the keyword 'End'.
The bit of HQL that generates this is:
"from UserSession where UserId = :userId and End is null"
In the generated SQL, there is this snippet:
where (UserId=@p0 )and(End is null )
I've gotten this before on table names since I have a penchant for using the most natural name for something even if it clashes with a reserved word (User and Order typically). I've used the backtick notation to escape table names, but for some reason it isn't working in this case.
Here's what I've tried:
Changing the HQL to the following:
"from UserSession where UserId = :userId and `End` is null"
and
"from UserSession where UserId = :userId and [End] is null"
I've also tried changing my mapping file so it maps the property like this:
<property name="End" column="`End`" />
and
<property name="End" column="[End]" />
None of these work. They all throw the same error, except for when I use the square brackets in the HQL. In that case it throws an error saying there were unexpected brackets.
Does anyone know how to resolve this without renaming my column?
Regards-
Eric
|