You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by "Hiller, Frank RD-AS2" <Fr...@heidelberg.com> on 2005/06/20 11:42:23 UTC

I would like to replace specific QueryBySQL by general QueryByCriteria

Hi OJB users,
 
I have a database table storing events combined with a timestamp, a
deviceID specifying the device where the event occured and a unique ID.
In some cases I have to know the latest event of a device that occured
before a certain timestamp.
At the moment I use QueryBySQL (see SQL statement below), but this
statement contains the Oracle specific TO_DATE formatter. I'd rather use
QueryByCriteria and define a Criteria object that can replace the SQL
statement (May be I have to use a differnt RDBMS and don't want to
change the source code).
 
SQL statement as follows:
select * from <tableName> where id = (select max(id) from (select * from
<tableName> where timestamp = (select max(timestamp) from <tableName>
where deviceid = '<deviceID>' and timestamp <
TO_DATE('<day>.<month>.<year>.<hour>:<minute>:<second>', 'DD.MM.YYYY
HH24.MI.SS'))))

Is there a way to define something like Criteria.addMin(...) or
Criteria.addMax(...) that could be helpful?
Is there a way to define nested queries like I use within the SQL
statement?
 
Thanks,
Frank