我正在将旧版应用程序的spring和hibernate版本从spring 3升级到spring 5,将hibernate3升级到hibernate5。为此,我正在使用spring-boot。 我们使用SQLServer作为数据库。其中一个Dao在查询中使用“ bitwise_and”从数据库中获取数据。
但是当它尝试查询时,它将失败,并带有以下异常:-
Caused by: java.sql.SQLException: 'bitwise_and' is not a recognized built-in function name.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:372)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2988)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2421)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:671)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:505)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:1029)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60)
... 57 common frames omitted
要启用bitwise_and运算符,将自定义SQLServerDialect配置如下:-
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.type.IntegerType;
public class CustomSQLServerDialect extends org.hibernate.dialect.SQLServerDialect {
public CustomSQLServerDialect() {
super();
registerFunction("bitwise_and", new StandardSQLFunction("bitwise_and", IntegerType.INSTANCE));
}
}
此自定义方言也已添加到SessionFactory的hibernateProperties中。
任何帮助将不胜感激。