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?

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.

Reply via email to