jakartaee / persistence

https://jakartaee.github.io/persistence/
Other
189 stars 55 forks source link

allow @NamedQuery and @NamedNativeQuery more control over query execution #473

Open gavinking opened 10 months ago

gavinking commented 10 months ago

Currently, a @NamedQuery or @NamedNativeQuery may specify query hints using the verbose and stringly-typed annotation @QueryHint.

I propose making certain "hints" available in a typesafe way, for example:

public @interface NamedQuery {
    ...
    FlushModeType flushMode() default AUTO;
    CacheStoreMode cacheStoreMode() default USE;
    CacheRetrieveMode cacheRetrieveMode() default USE;
    int timeout() default -1;
}

In the case of @NamedNativeQuery, it might even be useful to add a way to specify the tables or entities affected by a native query, to allow auto-flush to work correctly:

public @interface NamedNativeQuery {
    ...
    FlushModeType flushMode() default AUTO;
    CacheStoreMode cacheStoreMode() default USE;
    CacheRetrieveMode cacheRetrieveMode() default USE;
    int timeout() default -1;

   // control over auto-flush

    String[] affectedTables() default {};
    Class<?>[] affectedEntities() default {};
}