Refresh an Oracle Materialized view in a Spring Da

2019-06-07 20:08发布

问题:

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:

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()