分类的分页不使用Hibernate在Oracle数据库中工作
我正在使用Hibernate的Spring JPA。当我将分页用于排序(通常在表中)时,Oracle10Gdialect
select row_.*, rownum rownum_ from (
select table_.tablefield1, table_.tablefield2, table_.tablefield3...
from table table_ where <condition>
order by table_tablefield1 desc
) row_ where rownum <= 5
根据 this 解释,在这种情况下,命令不被视为Rownum更改子查询的顺序。 实际上,我正在遇到这个问题。如果我不放置任何分类字段,一切都很好。
我打开了a bug 在Hibernate Orm中,但自6个月以来没有反馈。有人可以帮忙吗?
环境 Spring Boot 2.2.0,Java 8,Linux,Oracle 19.0.0.0.0
备注! 这个问题不重复 this 一个,因为我无法更改Hibernate生成的SQL。在标记重复之前,请检查标签。
I'm using spring jpa with hibernate. When I use the pagination with sorting (typically in tables) the Oracle10gDialect generates the following SQL
select row_.*, rownum rownum_ from (
select table_.tablefield1, table_.tablefield2, table_.tablefield3...
from table table_ where <condition>
order by table_tablefield1 desc
) row_ where rownum <= 5
According to this explanation, the order by is in that case not considered as the rownum changes the order of the subquery.
And in fact I'm experiencing the issue. Everything works well if I don't put any sorting field.
I opened a bug in Hibernate ORM but no feedback since more than 6 months. Anybody can help?
Environment
Spring boot 2.2.0, Java 8, Linux, Oracle 19.0.0.0.0
REMARK!
This question does not duplicate this one because I can't change the SQL generated by hibernate. Please check the tags before marking as duplicate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我确实相信,HBN生成的SQL首先和下一个页面都是正确的。您实际上很可能面对
排序稳定性
问题:如果某些记录具有您要订购的列的相同值,我们对他们的顺序无话可说,Oracle也不能说。 ,要使排序稳定,您需要添加一些独特的东西(即id
)以按子句订购。您可能不会在其他DBS中遇到类似问题,因为其他DBS可能会使用聚类索引来支持PK。
是的,“现代语法”无法解决排序稳定性问题。
I do believe the SQLs generated by HBN to get both first and next pages are correct. It is more likely you are actually facing with
sort stability
issue: if some records has the same value of column you are ordering by, we can say nothing about their order, and oracle can't say as well, to make sort stable you need to add something unique (i.e.id
) to order by clause.You might not facing with similar issue in other DBs because other DBs might use clustered index to support PK.
And yes, "modern syntax" won't solve sort stability issue.
上面的语法没有错。它可以正常工作,
也许您指的是获取后续页面(2,3,4 ...) - 如果是这样,我们需要查看为此生成的查询。
There is nothing wrong with the syntax above. It works correctly
Perhaps you are referring to getting subsequent pages (2,3,4...) - if that is the case, we'd need to see the query generated for that.