The following query returns the latest 500 rows:
Code:
SELECT * FROM (SELECT * FROM ul_common_log_event WHERE application_name = 'Configuration' ORDER BY cle_id DESC) WHERE ROWNUM <= 500
This HQL query...
Code:
from CommonLogEvent cle where cle.componentIdentification.applicationName = 'Configuration' order by cle.id
with Query q = session.createQuery(query).setMaxResults(500);
produces this Oracle SQL, and returns no records... I'm not sure why two rowum statements are being created.
Code:
select * from ( select row_.*, rownum rownum_ from ( select commonloge0_.cle_id as cle_id, commonloge0_.observed_time as observed2_, commonloge0_.version as version, commonloge0_.situation as situation, commonloge0_.message as message, commonloge0_.status as status, commonloge0_.severity as severity, commonloge0_.log_level as log_level, commonloge0_.address_type as address_9_, commonloge0_.address_name as address10_, commonloge0_.component_name as compone11_, commonloge0_.application_name as applica12_, commonloge0_.instance_name as instanc13_, commonloge0_.thread_name as thread_14_, commonloge0_.environment_name as environ15_ from UL_COMMON_LOG_EVENT commonloge0_ where (commonloge0_.application_name='Configuration' ) order by commonloge0_.cle_id ) row_ where rownum <= ?) where rownum_ > ?
Unfortunately, adding the order by to my HQL does not do the trick. BTW I am using Hiberante 2.1.1. I know that Hibernate supports sub-selects, so I am hoping there is a way to reproduce my Oracle TOP-N query