我遇到了使用以下代码刷新物化视图(POSGRESQL)的麻烦:
String hql = "refresh materialized view mv_all_operations; refresh materialized view mv_all_members;"; createQuery(hql).executeUpdate();
例外:
antlr.NoViableAltException: unexpected token: refresh at org.hibernate.hql.internal.antlr.HqlBaseParser.statement(HqlBaseParser.java:169) ~[hibernate-core-4.2.7.Final.jar:4.2.7.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:268) ~[hibernate-core-4.2.7.Final.jar:4.2.7.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182) ~[hibernate-core-4.2.7.Final.jar:4.2.7.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138) ~[hibernate-core-4.2.7.Final.jar:4.2.7.Final] at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:105) [hibernate-core-4.2.7.Final.jar:4.2.7.Final] at org.hibernate.engine.query.spi.HQLQueryPlan. (HQLQueryPlan.java:80) [hibernate-core-4.2.7.Final.jar:4.2.7.Final] at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168) [hibernate-core-4.2.7.Final.jar:4.2.7.Final] at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221) [hibernate-core-4.2.7.Final.jar:4.2.7.Final] at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199) [hibernate-core-4.2.7.Final.jar:4.2.7.Final] at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1784) [hibernate-core-4.2.7.Final.jar:4.2.7.Final]
看来我无法以这种方式更新我的视图,但是我找不到在代码中进行此操作的任何其他机会。有什么建议么?
使用本机查询而不是hql。
String sql = "refresh materialized view mv_all_operations; refresh materialized view mv_all_members;"; createNativeQuery(sql).executeUpdate();