我有以下代碼從一個Oracle數據庫的單個表中執行簡單的查詢。簡化休眠查詢
entityManager.createQuery(
"SELECT a FROM " + Person.class.getSimpleName()
+ " a WHERE lower(a.firstName) = '" + firstName + "'")
.getSingleResult();
的Hibernate產生的SQL語句:
select
*
from
(select
person0_.id as id75_,
person0_.FIRSTNAME as FIRSTNAME75_,
person0_.LASTNAME as LASTNAME75_
from
PERSONS person0_
where
lower(person0_.FIRSTNAME)='john')
where
rownum <= ?
我們的DBA表明該查詢應該對性能方面的原因更簡單。我怎樣才能讓Hibernate來簡化查詢 這樣的:
select ID, FIRSTNAME, LASTNAME from PERSONS
where lower(FIRSTNAEM) = 'john' and rownum <= 1
感謝
首先,我將在FIRSTNAME字段上創建一個索引。 – 2013-03-15 10:14:39
@StefanBe:當where子句使用函數時,該索引將被忽略。你需要一個功能索引... – beny23 2013-03-15 10:15:26
啊好的。不知道 – 2013-03-15 10:16:54