JPA Native Query Returns Entity Instead of Array ------------------------------------------------
Key: CAMEL-3635 URL: https://issues.apache.org/jira/browse/CAMEL-3635 Project: Camel Issue Type: Improvement Components: camel-jpa Environment: Hibernate 3.4.0.GA and DB2 9.7 Reporter: Mark Borner I'm in a bit of a pickle. I'm trying to use a JPA endpoint as a consumer. I first started by using the "consumer.namedQuery" option to use Hibernate HQL from the entity's @NamedQuery annotation. This worked well and the endpoint return the persistence entity. Now I've had to modify my SQL to use the fragment "FETCH FIRST 1 ROW ONLY". This fragment isn't supported by HQL - in fact there is no way that I've found to limit results using HQL (if there is one, please let me know!). So I've switched the JPA endpoint to use the "consumer.nativeQuery" (which uses the SQL specified on the nativeQuery parameter). This works, but per the documentation, it doesn't return the persistence entity - it returns an array of String's representing the returned columns of the query. So I'm stuck - I can't use "consumer.namedQuery" and I can't use "consumer.nativeQuery" to retrieve the persistence entity. For reference, here is my native SQL: select * from GTWY.EXPORT_MESSAGE x where x.STATUS in ('RECEIVED', 'RERUN') and x.INTERNAL_ID = (select y.INTERNAL_ID from GTWY.EXPORT_MESSAGE y join GTWY.MESSAGE m on m.INTERNAL_ID = y.INTERNAL_ID where y.HISTORY_ID = x.HISTORY_ID order by m.CREATED ASC fetch first 1 row only) I'm wondering why the choice was made to return an array of String's when using the nativeQuery option? In QueryBuilder.nativeQuery() it is calling entityManager.createNativeQuery(nativeQuery). If it called EntityManager.createNativeQuery(String sqlString, *Class resultClass*) or even EntityManager.createNativeQuery(String sqlString, *String resultSetMapping*) we could return the actually persistence entity, correct? Would you consider making this enhancement? -- This message is automatically generated by JIRA. - For more information on JIRA, see: http://www.atlassian.com/software/jira