In @Query(value = “SELECT cast((EXTRACT(HOUR FROM AVG(j.finished - j.started)) * 3600 * 1000 + EXTRACT(MINUTE FROM AVG(j.finished - j.started)) * 60 * 1000 + EXTRACT(SECOND FROM AVG(j.finished - j.started)) * 1000 + EXTRACT(MILLISECONDS FROM AVG(j.finished - j.started))) as long) FROM JobFile jf LEFT JOIN jf.job j WHERE j.finished >= :date AND j.status = 2 AND jf.advancedProcessing = :advanced”)
Long getAverageTimeAdvanced(@Param(“date”) Date date, @Param(“advanced”) boolean b);
I face the following exception after update
Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.Date org.epo.cc.file.malwareinspector.hibernate.repository.JobRepository.getAverageTimeAdvanced(java.util.Date,boolean)
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:100)
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.(SimpleJpaQuery.java:70)
at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:60)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:170)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:252)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:95)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:111)
… 92 more
Caused by: java.lang.IllegalArgumentException: org.hibernate.query.SyntaxException: At 1:218 and token ‘FROM’, no viable alternative at input ‘SELECT cast((EXTRACT(HOUR FROM AVG(j.finished - j.started)) * 3600 * 1000 + EXTRACT(MINUTE FROM AVG(j.finished - j.started)) * 60 * 1000 + EXTRACT(SECOND FROM AVG(j.finished - j.started)) * 1000 + EXTRACT(MILLISECONDS *FROM AVG(j.finished - j.started))) as date) FROM JobFile jf LEFT JOIN jf.job j WHERE j.finished >= :date AND j.status = 2 AND jf.advancedProcessing = :advanced’ [SELECT cast((EXTRACT(HOUR FROM AVG(j.finished - j.started)) * 3600 * 1000 + EXTRACT(MINUTE FROM AVG(j.finished - j.started)) * 60 * 1000 + EXTRACT(SECOND FROM AVG(j.finished - j.started)) * 1000 + EXTRACT(MILLISECONDS FROM AVG(j.finished - j.started))) as date) FROM JobFile jf LEFT JOIN jf.job j WHERE j.finished >= :date AND j.status = 2 AND jf.advancedProcessing = :advanced]
The query looks fine to me syntax-wise, is you entity named JobFile? Please post the full stack trace of the Hibernate SyntaxException, not the Spring error that’s wrapping it please.
Caused by: org.hibernate.query.SyntaxException: At 1:218 and token ‘FROM’, no viable alternative at input ‘SELECT cast((EXTRACT(HOUR FROM AVG(j.finished - j.started)) * 3600 * 1000 + EXTRACT(MINUTE FROM AVG(j.finished - j.started)) * 60 * 1000 + EXTRACT(SECOND FROM AVG(j.finished - j.started)) * 1000 + EXTRACT(MILLISECONDS *FROM AVG(j.finished - j.started))) as long) FROM JobFile jf LEFT JOIN jf.job j WHERE j.finished >= :date AND j.status = 2 AND jf.advancedProcessing = :advanced’ [SELECT cast((EXTRACT(HOUR FROM AVG(j.finished - j.started)) * 3600 * 1000 + EXTRACT(MINUTE FROM AVG(j.finished - j.started)) * 60 * 1000 + EXTRACT(SECOND FROM AVG(j.finished - j.started)) * 1000 + EXTRACT(MILLISECONDS FROM AVG(j.finished - j.started))) as long) FROM JobFile jf LEFT JOIN jf.job j WHERE j.finished >= :date AND j.status = 2 AND jf.advancedProcessing = :advanced]
at org.hibernate.query.hql.internal.StandardHqlTranslator$1.syntaxError(StandardHqlTranslator.java:109) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:41) ~[antlr4-runtime-4.13.0.jar:4.13.0]
at org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:544) ~[antlr4-runtime-4.13.0.jar:4.13.0]
at org.antlr.v4.runtime.DefaultErrorStrategy.reportNoViableAlternative(DefaultErrorStrategy.java:310) ~[antlr4-runtime-4.13.0.jar:4.13.0]
at org.antlr.v4.runtime.DefaultErrorStrategy.reportError(DefaultErrorStrategy.java:136) ~[antlr4-runtime-4.13.0.jar:4.13.0]
at org.hibernate.grammars.hql.HqlParser.queryExpression(HqlParser.java:2072) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.grammars.hql.HqlParser.selectStatement(HqlParser.java:410) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.grammars.hql.HqlParser.statement(HqlParser.java:340) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.query.hql.internal.StandardHqlTranslator.parseHql(StandardHqlTranslator.java:133) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.query.hql.internal.StandardHqlTranslator.translate(StandardHqlTranslator.java:67) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.createHqlInterpretation(QueryInterpretationCacheStandardImpl.java:145) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.resolveHqlInterpretation(QueryInterpretationCacheStandardImpl.java:132) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.internal.AbstractSharedSessionContract.interpretHql(AbstractSharedSessionContract.java:802) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:852) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
… 162 common frames omitted
You didn’t reply. If you think this is an Hibernate bug, I suggest trying to reproduce the problem using our test case template and if you are able to reproduce the issue, create a new ticket in our issue tracker and attach that reproducer .
CREATE TABLE job_file(
id BIGSERIAL NOT NULL,
status INT NOT NULL,
allowed INT NOT NULL,
job_id UUID NOT NULL,
file_id BIGINT NOT NULL,
file_path VARCHAR(255) NOT NULL,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
uid VARCHAR(255),
mdc_data_id VARCHAR(32),
mdc_server VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (job_id)
REFERENCES job(id)
ON DELETE CASCADE,
FOREIGN KEY (file_id)
REFERENCES uploaded_file(id)
ON DELETE CASCADE
);
I’m asking you about your entity name and you are pasting DDL statements, I don’t know what that has to do with it. HQL language is based on your domain model, so entity names and java properties rather than SQL tables / column.
I already told you how to proceed if you believe this is an Hibernate bug, otherwise if you won’t provide the details I asked for I cannot help you further.
Once again, I don’t see any issues from the Hibernate side, but I cannot help you with any of the other components your application is using. The only suggestion I can give you is, once again, to try reproducing the issue using Hibernate only if you believe this might be an Hibernate bug.