I would love to develop a fix, but the project I'm working on doesn't afford me any free time. I've opened a Jira here:
https://issues.apache.org/jira/browse/CAMEL-3635 Thanks, Mark Mark Borner Java Developer - ZStream Xpress From: Claus Ibsen <claus.ib...@gmail.com> To: users@camel.apache.org Date: 04/02/2011 05:14 PM Subject: Re: JPA Quandary On Fri, Feb 4, 2011 at 4:06 AM, Mark Borner <mark.bor...@zurich.com.au>wrote: > > Hi all: > > 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? > > Yeah that sounds like a good enhancement. You are welcome to file a JIRA entry And we love contributions, so you are welcome to work on a patch. I assume we should add a consumer.resultClass option so you can specify the class in the uri, that the native query can leverage. Use the ClassResolver from the CamelContext to get the Class type. That ensures it works in different environments such as OSGi, JBoss, Tomcat etc. Links to JIRA here: http://camel.apache.org/support Here are the version's of software I'm using: > > Hibernate 3.4.0.GA > DB2 9.7 > Camel 2.5.0 > > Thanks, > Mark > > Mark Borner > Java Developer - ZStream Xpress > > > > > ---- > This email is intended for the named recipient only. It may contain > information which is confidential, commercially sensitive, or > copyright. If you are not the intended recipient you must not > reproduce or distribute any part of the email, disclose its contents, > or take any action in reliance. If you have received this email in > error, please contact the sender and delete the message. It is your > responsibility to scan this email and any attachments for viruses and > other defects. To the extent permitted by law, Zurich and its > associates will not be liable for any loss or damage arising in any > way from this communication including any file attachments. We may > monitor email you send to us, either as a reply to this email or any > email you send to us, to confirm our systems are protected and for > compliance with company policies. Although we take reasonable > precautions to protect the confidentiality of our email systems, we > do not warrant the confidentiality or security of email or > attachments we receive. > > -- Claus Ibsen ----------------- FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/ ---- This email is intended for the named recipient only. It may contain information which is confidential, commercially sensitive, or copyright. If you are not the intended recipient you must not reproduce or distribute any part of the email, disclose its contents, or take any action in reliance. If you have received this email in error, please contact the sender and delete the message. It is your responsibility to scan this email and any attachments for viruses and other defects. To the extent permitted by law, Zurich and its associates will not be liable for any loss or damage arising in any way from this communication including any file attachments. We may monitor email you send to us, either as a reply to this email or any email you send to us, to confirm our systems are protected and for compliance with company policies. Although we take reasonable precautions to protect the confidentiality of our email systems, we do not warrant the confidentiality or security of email or attachments we receive.