I have to modify some Java Code, and a portion of it uses Hibernate to query an Oracle database. I am VERY familiar with Oracle, fairly familiar with Java and Eclipse(used for this project), and very little with Hibernate.
I have read some of the documentation on Hibernate, and I believe I found the function that I needed, but I want to make sure it will work as I believe it should.
The existing query string is as follows.
requestList = session.find("select r from Hl7OutRequest as r join fetch r.hl7OutStatus as s where s.statusCd = ? order by r.requestId", status, Hibernate.STRING);
The problem is that the field "requestId" has a cardinality of 5, we have Oracle Standard Edition, and the index on this field is a standard BTree index. Hence, the Oracle CBO will tell Oracle to do a full table scan every time this executes. FYI, there are over 1,000,000 rows.
There is another field in the table called "CREATE_DATE"(mapped as "createDate" in the HBM XML file). So, I have modified the code to include the concept of a "lag Time", which is read from the XML configuration file for the application. In a nutshell, it will tell Oracle to only look for messages with a status of "whatever status chose(1, 2, 3, 4, or 5) and created after a certain date/time. I have also created a composite index on the table with "CREATE_DATE" and "STATUS_ID".
My question is whether or not HQL will accept the following. The "getQueueLagTime()" call will return a string copy of the float variable this is the number of hours in days unit. So, if I want thirty minutes, it will be the string "0.021". So, it is basically "current_timestamp() - 0.021". Will HQL parse this correctly? It does not need to be a bind variable, because it will always be the same the whole time it is running. It runs nonstop.
requestList = session.find("select r from Hl7OutRequest as r join fetch r.hl7OutStatus as s where r.createDate >= (current_timestamp() - " + MessageGeneratorProperties.getInstance().getQueueLagTime() + ") and s.statusCd = ? order by r.requestId", status, Hibernate.STRING);
Sorry for such a boring newbie question!
|