persistence icon indicating copy to clipboard operation
persistence copied to clipboard

distinction between typed (selection) queries and update queries

Open gavinking opened this issue 8 months ago • 6 comments

We currently don't have a very clean or well-defined split between TypedQuery, which I claim should always represent a select query, and update/delete queries, which I claim should always be executed via the untyped supertype Query.

This sorta reflects the fact that TypedQuery was hacked on later in JPA 2.0.

In fact, it's quite arguable that Persistence 3.2 lets you execute a named update query using TypedQuery<Void> obtained via a TypedQueryReference. I don't recall if we really intended that, but even if we did, I don't think it's great.

As a first step to cleaning this up I would:

  1. override and deprecate executeUpdate() on TypedQuery
  2. introduce the (unparameterized) type QueryReference to represent untyped queries

A further optional step might be to introduce a dedicated interface for executing update/delete queries (the equivalent of Hibernate's MutationQuery) which subtracts all the operations of Query which are only relevant to select queries. I'm not sure of the best way to do this, and I'm concerned about introducing an explosion of createQuery() operations, so perhaps it's not worth going this far.

gavinking avatar Apr 24 '25 09:04 gavinking