我正在使用SQL Server和Sping Boot 3.0.2以及HIBERNATE 6.1,我的JPA查询如下所示。
(t1.col1 | t1.col2) = :notIntOnly
我的自定义SQLServer2012DialectCustom
代码
@Override
public void contribute(MetadataBuilder metadataBuilder) {
metadataBuilder.applySqlFunction(
"(?1 | ?2)",
new StandardSQLFunction(
"(?1 | ?2)",
StandardBasicTypes.INTEGER
)
);
}
但我已经低于误差了
Caused by: org.hibernate.query.SemanticException: A query exception occurred []
at org.hibernate.query.hql.internal.StandardHqlTranslator.parseHql(StandardHqlTranslator.java:130)
at org.hibernate.query.hql.internal.StandardHqlTranslator.translate(StandardHqlTranslator.java:77)
at org.hibernate.internal.AbstractSharedSessionContract.lambda$createQuery$2(AbstractSharedSessionContract.java:747)
at org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.createHqlInterpretation(QueryInterpretationCacheStandardImpl.java:141)
at org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.resolveHqlInterpretation(QueryInterpretationCacheStandardImpl.java:128)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:744)
... 70 common frames omitted
Caused by: org.hibernate.query.sqm.ParsingException: line 1:146 no viable alternative at input '|'
at org.hibernate.query.hql.internal.StandardHqlTranslator$1.syntaxError(StandardHqlTranslator.java:46)
at org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:41)
at org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:543)
at org.antlr.v4.runtime.DefaultErrorStrategy.reportNoViableAlternative(DefaultErrorStrategy.java:310)
at org.antlr.v4.runtime.DefaultErrorStrategy.reportError(DefaultErrorStrategy.java:136)
at org.hibernate.grammars.hql.HqlParser.queryExpression(HqlParser.java:1180)
at org.hibernate.grammars.hql.HqlParser.selectStatement(HqlParser.java:382)
at org.hibernate.grammars.hql.HqlParser.statement(HqlParser.java:313)
at org.hibernate.query.hql.internal.StandardHqlTranslator.parseHql(StandardHqlTranslator.java:116)
... 75 common frames omitted
1条答案
按热度按时间1aaf6o9v1#
您用来注册“函数”的代码不起作用。您不能在“名称”
(?1 | ?2)
下注册函数。您必须在字母数字名称下注册函数,例如bit_or
并在查询中以如下方式使用它: