我有以下代码,它从 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 建议此查询应该更简单。如何使休眠以简化查询,如下所示:
select ID, FIRSTNAME, LASTNAME from PERSONS
where lower(FIRSTNAEM) = 'john' and rownum <= 1
谢谢