我在Oracle数据库11.2.0.1.0中有这种奇怪的行为。
使用此表:
CREATE TABLE "COMPANIES"
( "ID" NUMBER(19,0) NOT NULL ENABLE,
"COMMENTS" VARCHAR2(3999 CHAR),
"NAME" VARCHAR2(126 CHAR) NOT NULL ENABLE,
"IDENTIFICATIONCODE" VARCHAR2(126 CHAR),
"REMOVALDATE" TIMESTAMP (6),
"BLACKLIST" NUMBER(1,0) DEFAULT 0 NOT NULL ENABLE,
"BLACKLISTREASON_ID" NUMBER(19,0),
"BLACKLISTCOMMENTS" VARCHAR2(3999 CHAR),
CONSTRAINT "COMPANIES_PK" PRIMARY KEY ("ID")
此查询返回以下结果集:
SELECT id643_1_, blacklist643_1_ FROM (
select this_.id AS id643_1_,this_.blacklist AS blacklist643_1_
from companies this_
where this_.id IN (
SELECT DISTINCT this2_.id AS y0_
FROM companies this2_
WHERE ( this2_.removaldate IS NULL OR this2_.removaldate >= to_timestamp('03/06/2019 00:00:00.000','mm/dd/yyyy hh24:mi:ss.ff3')))
ORDER BY this_.name ASC
) WHERE ROWNUM <= 2147483647;
id643_1_ blacklist643_1_
3869594 [NULL]
3869596 [NULL]
3869597 [NULL]
3869592 [NULL]
3869598 [NULL]
3869599 [NULL]
但是删除ROWNUM过滤器:
SELECT id643_1_, blacklist643_1_ FROM (
select this_.id AS id643_1_,this_.blacklist AS blacklist643_1_
from companies this_
where this_.id IN (
SELECT DISTINCT this2_.id AS y0_
FROM companies this2_
WHERE ( this2_.removaldate IS NULL OR this2_.removaldate >= to_timestamp('03/06/2019 00:00:00.000','mm/dd/yyyy hh24:mi:ss.ff3')))
ORDER BY this_.name ASC
)
--WHERE ROWNUM <= 2147483647;
id643_1_ blacklist643_1_
3869594 0
3869596 0
3869597 0
3869592 0
3869598 0
3869599 0
或内部的“ IN”过滤器:
SELECT id643_1_, blacklist643_1_ FROM (
select this_.id AS id643_1_,this_.blacklist AS blacklist643_1_
from companies this_
--where this_.id IN (
--SELECT DISTINCT this2_.id AS y0_
--FROM companies this2_
--WHERE ( this2_.removaldate IS NULL OR this2_.removaldate >= to_timestamp('03/06/2019 00:00:00.000','mm/dd/yyyy hh24:mi:ss.ff3')))
--ORDER BY this_.name ASC
)
WHERE ROWNUM <= 2147483647;
id643_1_ blacklist643_1_
3869594 0
3869596 0
3869597 0
3869592 0
3869598 0
3869599 0
它返回正确的默认值!
查询别名是休眠生成的,尽管如此,它已经在jvm外部进行了测试,所以我认为这不是休眠的也不是与jpa相关的问题。
我不知道为什么会这样。
UPDATE1:
类似的表格,类似的查询:
select * from (
select *
from incidents this_
where this_.id in (select tab2.id from incidents tab2)
order by this_.id
) where rownum <= 1000;
id BLACKLIST FAILED FAILEDDATE
1100071 0 0 [NULL]
1100112 0 1 2013-01-28 00:00:00
1100155 0 0 [NULL]
1100203 0 0 [NULL]
1100241 0 0 [NULL]
1100301 0 0 [NULL]
具有更大的ROWNUM:
select * from (
select *
from incidents this_
where this_.id in (select tab2.id from incidents tab2)
order by this_.id
) where rownum <= 1000000;
id BLACKLIST FAILED FAILEDDATE
1100071 [NULL] [NULL] [NULL]
1100112 [NULL] [NULL] [NULL]
1100155 [NULL] [NULL] [NULL]
1100203 [NULL] [NULL] [NULL]
1100241 [NULL] [NULL] [NULL]
1100301 [NULL] [NULL] [NULL]
UPDATE2:
在11.2.0.3.0上不会发生,所以我想这是一个错误。如果有人遇到这个问题,我将保留一个未解决的问题。