Alex
Alex

Reputation: 243

Refresh an Oracle Materialized view in a Spring Data Repository

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?

Upvotes: 1

Views: 6008

Answers (1)

Jens Schauder
Jens Schauder

Reputation: 81990

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

Upvotes: 6

Related Questions