We have a data table where it has a function based index (database is Oracle). But in our Java EE ejb application, system accesses the data using jpa queries.
But in order to force the oracle to use the function based index instead of doing a full table scan, I need a way to tell the jpa container to generate the sql with the function defined in the index in the WHERE clause of the sql query.
As far as I know, we have to use native queries for creating customizations in the generated queries like that. But in order to use native queries we have to do many code changes. Could anyone please suggest any other work around for solving this issue?
Index: (We needed to enforce unique constraint for Dev_Id + Dev_Type, but sometimes Dev_Id can be null while Dev_Type can be duplicated.)
(NVL2(Dev_Id, Dev_Id, NULL), NVL2(Dev_Id, Dev_Type, NULL))
Query we need: (In order to use the index)
Select * from some_table where NVL2(Dev_Id, Dev_Id, NULL) = 'some_val';
Container generated query:
Select * from some_table where Dev_Id = 'some_val';
NVL2(Dev_Id, Dev_Id, NULL)redundant? And can't you just add an index on Dev_Id?