JPA says this is not supported. However it does not *explicitly* say it is not supported - it just "strongly implies" that it should be the column's "JDBC type" (the type of the column value in the ResultSet) in both the spec and its Javadoc. E.g.,
{code} public @interface ColumnResult { ...
/** * (Optional) The Java type to which the column type is to be mapped. * If the <code>type</code> element is not specified, the default JDBC type * mapping for the column will be used. * @since Java Persistence 2.1 */ Class type() default void.class; } {code}
However this is useful, for example, when you are selecting ({{@ColumnResult}}) as, e.g. a String.class, but want to use it as an argument of a {{ @ ConstructorResult}} which is a converted value. We could handle, e.g.:
{code} @ConstructorResult( Project.class, columns={ ..., @ColumnResult( "status", MyStatusConverter.class ) } )
enum Status { ... }
class MyStatusConverter implements AttributeConverter<Status,String> { ... }
class Project { ...
Project(..., Status status) { ...} ... }
{code}
We could also implement "easy button" support for cases where we have a {{{ColumnResult}} with a {{#type}} of String or int used as the "JDBC type" used as an argument that to a {{ConstructorResult}} where the argument on the constructor is an enum. This would leverage our {{@Enumerated}} support. |
|