oracle where in limitation to 1000 / hibernate

∥☆過路亽.° 提交于 2019-12-21 12:17:31

问题


Oracle knows the limitation to 1000 elements in the where a in (..) clause. Does this limitation also exist when using Hibernate in conjuction with Oracle?


回答1:


This database limitation still exists with hibernate. If you really need to have more than 1000 items in your in clause you will have to split the list yourself in the code and run the query for each block of 1000 keys, then append the result sets together.

Note this hack breaks down if your query needs to sort or otherwise aggregate the results of the query because the full set of results will only be known in the code. In this case you are better of finding another way to write the query that does not require an IN clause.




回答2:


We had the same issue and solved it by splitting it up into 100er packages of IN clause

select * from mytable where id in (...) or id in (...).

Remarks:

  • make sure that you use bind variables
  • make sure that the query always looks the same. This is done by filling up the IN clauses with -1 until you have 100 elements in it
  • try to use always the same number of ORed in(...) so that the query always looks to same

Why you want the points above? It is so that the query optimizer can reuse the query plan.

Additional optimization:

  • instead of using -1, you can just use the very last true value again. That is even a little bit better.

example: in(1, 2, 3, 4, 4, ..., 4)

Note also: we tested with various fixed numbers of elements in the in clause and observed decreased performances for a lot than 100 elements.




回答3:


Yes as Hibernate will call Oracle at some stage so the limit is the lowest of the limits in Hibernate and Oracle

Hibernate does nothing special with data for an in - just passes it to the database




回答4:


It seems to be a Bug in Hibernate:

http://opensource.atlassian.com/projects/hibernate/browse/HHH-1123



来源:https://stackoverflow.com/questions/1673521/oracle-where-in-limitation-to-1000-hibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!