We have a Hibernate (Java) query that looks in a SQL Server table called MARK for a database row, searching by a (primary) key value SYMBOL which is VARCHAR.
What’s happening is that the parameter type in the incoming query is mapped to NVARCHAR, even though the column is VARCHAR.
E.g.:
Code:
(@P0 nvarchar(4000))SELECT…
This forces the lookup to full scan the index, instead of seeking out the key. When we tried to change the datatype directly, or even repoint this query to an indexed view that applied the type conversion, we got an error such as:
org.hibernate.HibernateException: Wrong column type in <database>.dbo.MARK for column SYMBOL. Found: nvarchar, expected: varchar(255)The question is, how can we guide Hibernate to map string values to VARCHAR instead of NVARCHAR by default?