[jpa-spec users] Allow to define _at_Named*Queries and on any CDI discovered type

From: Guillermo González de Agüero <>
Date: Thu, 27 Apr 2017 19:47:01 +0200


Following the CDI integration movement we've seen on other specs, I to
propose to expand the places where @NamedQueries, @NamedNativeQueries and
@NamedStoreProcedureQueries (and possibily some more I'm missing), to
aknowledge every discovered type by CDI [1], instead of just @Entity
annotated classes.

In most cases, entities are the best place to place that annotations, but:
- Stored procedures often don't return an entity, and usually they are not
even related with an entity, but just perform some business work and return
a result code. In that case, the bussines component would be a better place
to put it.
- Both JPQL and native queries can return non entity objects. JPQL through
the NEW operator, and native queries through @ConstructorResultset.
Annotating the resulting DTO would be more natural that annotating an
entity that has nothing to do with it.

Of course, we can define them in XML [2], but I find it cumbersome and IDE
support is not very good (at least on NetBeans).

Allowing to use those annotations on CDI managed beans wouldn't be enough,
as the DTOs probably won't be managed beans anyway. But searching for the
annotations on every CDI discovered type [1] would account for the majority
of use cases and provide a unified experience.

What do you all think?


Guillermo González de Agüero