Skip to content

annotations for static queries usable in Jakarta Data #780

@gavinking

Description

@gavinking

Since:

  1. allow @NamedQuery and @NamedNativeQuery more control over query execution #473 has run aground, and
  2. it would be nice to have a similar capability to the one proposed in allow @NamedQuery and @NamedNativeQuery more control over query execution #473 for use with Jakarta Data,

we could consider adding some kind of replacement/alternative to @NamedQuery, with the following differences:

  • The annotation could be placed at the method level
  • The name would be optional
  • There would be a full range of options like CacheXxxxModes, timeouts, etc.

That is, Jakarta Persistence would define its own "query annotation" in the sense of the Jakarta Data spec.

This is straightforward to add; the main barrier is that I have no idea what a reasonable name for this annotation would be. We can't call it @JPQL or @JpqlQuery or whatever because the query language isn't called that anymore. We can't call it @NamedQuery for multiple reasons. And we can't call it just @Query, also for multiple reasons. Nor does @EntityQuery work, since such queries are not required to return entities. I suppose @PersistenceQuery is available, but that's awful. The best option I've thought of so for is @QueryWithOptions or @QueryWithHints but ugghh.

Can anyone think of a reasonable name?

Now, an alternative solution, which works for Jakarta Data, but doesn't really help solve the need in #473 is that we could introduce a @QueryOptions or @QueryHints annotation that's meant to be used together with Jakarta Data's @Query. So you would write:

@Query("from Book")
@QueryOptions(cacheStoreMode = BYPASS)
List<Book> allBooks()

The problem is that this annotation is completely useless in Jakarta Persistence. It's only useful in Jakarta Data, which makes it an uncomfortable thing to have in this spec.

Note that this issue is very similar to #735.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions