Hiya, brand-newbie here.
While I'm actually using SQL Server 2000 for a project, but I'm forced to set it to SQL Server 6.5 compatibility, which means if I want to select out only 10 results, I cannot use LIMIT, nor can I use TOP -- 6.5 uses "SET ROWCOUNT(#); ... SET ROWCOUNT(0);"
I tried both SQL Server drivers, but Hibernate -- I'm using 3.0.5 -- only goes back in compatibility as far as SQL Server 7, because when I setMaxResults(10) during a query, the generated query is trying to use the TOP keyword, which is, of course, throwing an exception.
I've created a SQLServer65Dialect class (subclassing org.hibernate.dialect.SQLServer7Dialect) which simply overrides the getLimitString(String querySelect, int offset, int limit) method as follows:
Code:
public String getLimitString(String querySelect, int offset, int limit) {
if (offset>0) throw new UnsupportedOperationException("sql server has no offset");
return new StringBuffer( querySelect.length()+8 )
.append("SET ROWCOUNT " + limit + "; ")
.append(querySelect)
.append("; SET ROWCOUNT 0;") // Resetting the rowcount to unlimited
.toString();
}
I'm assuming there was no other way, since SQLServerDialect is for SQL Server 2K and SQLServer7Dialect clearly only goes back so far as 7.0 compliance. If I'm not wrong in that, should I submit this class via JIRA?
Thanks,
Jim