gpt4 book ai didi

Hibernate刷新物化 View

转载 作者:行者123 更新时间:2023-12-02 23:35:31 26 4
gpt4 key购买 nike

我遇到了使用以下代码刷新物化 View (POSGRESQL)的麻烦:

String hql = "refresh materialized view mv_all_operations; refresh materialized view mv_all_members;";
createQuery(hql).executeUpdate();

异常(exception):

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.<init>(HQLQueryPlan.java:105) [hibernate-core-4.2.7.Final.jar:4.2.7.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(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();

关于Hibernate刷新物化 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34202096/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com