jakartaee / persistence

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

allow nested result set mappings in @NamedNativeQuery #471

Closed gavinking closed 10 months ago

gavinking commented 10 months ago

The @SqlResultSetMapping annotation defines a named mapping, which is useful when you're passing a SQL query as a string to EntityManager.createNativeQuery().

But when you have a @NamedNatiiveQuery it's just annoying and untypesafe.

I therefore propose adding the following members to @NamedNatiiveQuery:

public @interface NamedNativeQuery { 

    ...

    /** Specifies the result set mapping to entities. */
    EntityResult[] entities() default {};

    /** 
     * Specifies the result set mapping to constructors. 
     */
    ConstructorResult[] classes() default {};

    /** Specifies the result set mapping to scalar values. */
    ColumnResult[] columns() default {};
}

Naturally, this is just a copy/paste job of the members of @SqlResultSetMapping.