[hibernate-dev] DTO Projection support for native queries?
Steve Ebersole
steve at hibernate.org
Fri Aug 18 11:16:34 EDT 2017
That error might be the manifestation of the problem, but its just a
symptom of the fact that this is not supported. The type passed in to type
the query must match what is selected (your "...").
And in fact JPA and Hibernate *do* support this, just not the way you do
it. You have to use a ResultSet mapping (see
@javax.persistence.SqlResultSetMapping). You'd specify
a javax.persistence.ConstructorResult.
Hibernate has an alternative means to support this using
a org.hibernate.transform.ResultTransformer
On Fri, Aug 18, 2017 at 9:47 AM Arnold Gálovics <galovicsarnold at gmail.com>
wrote:
> Hi all,
>
> I'm particularly interested in the usecase when you want to have a DTO
> projection from a native query. Currently as far as I know this is not
> supported through the JPA API.
>
> If I say entityManager.createNativeQuery("...", SomeDTO.class) Hibernate
> says SomeDTO is not an entity, at least that's what I remember.
>
> Now I implemented the support for the Tuple type for native queries, so
> implementing the support for DTO projections shouldn't be an issue.
>
> Is there any reason why this is not supported yet?
>
> Thanks in advance!
>
> Best,
> Arnold
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>
More information about the hibernate-dev
mailing list