Refresh an Oracle Materialized view in a Spring Da

2019-06-07 19:56发布

I need to refresh a materialized view in an Oracle database before I query the Spring Data Repository. I'm attempting to do this via a function in the Repository with a native query, like the following.

@Query("BEGIN DBMS_SNAPSHOT.REFRESH('MY_VIEW', 'C'); END;", nativeQuery = true)
fun refreshMaterializedView()

However, I am getting java.lang.NegativeArraySizeException when calling this method, although it works fine when being run directly on the database. What am I doing wrong here? Is there an alternative way to force the materialized view to refresh?

1条回答
Viruses.
2楼-- · 2019-06-07 20:06

You need to annotate your method with @Modifying. It is really intended for DML statements but works for this as well.

@Modifying
@Query("BEGIN DBMS_SNAPSHOT.REFRESH('MY_VIEW', 'C'); END;", nativeQuery = true)
fun refreshMaterializedView()
查看更多
登录 后发表回答