[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1123) Cannot put more than 1000 elements in a InExpression

Haavar Valeur (JIRA) noreply at atlassian.com
Thu Dec 1 00:39:22 EST 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1123?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44486#comment-44486 ] 

Haavar Valeur commented on HHH-1123:
------------------------------------

I would really like some sort of solution for this. I see a lot of copy and paste code to break the parameters into subsets. 

I agree we should take a step back. Obviously I can't speak for everybody, but I don't think the most common problem is really people doing a select, with 1000+ parameters. I think if we looked closer at the real problems people are having, we might be other ways of solving them.

I think the most common cases I've seen are that we needed the keys from a batch delete. In a particular case that's fresh in my mind, there was an external service that needed to be notified when records were purged. The way I ended solving it was breaking it into two queries, first I selected all the keys that was going to be deleted and then I issued a delete query with the set of keys as a parameter. I did not want to issue the delete query with the same criteria as the select in case the data changed between the select and delete. The result was a nice ticking timebomb, triggered when the purged set grew to a 1000 :).

The cases I've dealt with could be solved if I could access the set of primary keys after an update or delete. 


> Cannot put more than 1000 elements in a InExpression
> ----------------------------------------------------
>
>                 Key: HHH-1123
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1123
>             Project: Hibernate Core
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 3.1 rc2, 3.2.0.alpha1
>         Environment: Oracle 9i
>            Reporter: Alexis Seigneurin
>            Assignee: Strong Liu
>         Attachments: Animal.hbm.xml, hibernate-inexpression-oracle-3.2.patch, HQLHelper.java, LongInElementsTest.java, patch.txt
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The number of elements that we can put in a "in" expression is limited to a certain amount (1000 for Oracle, for instance). When creating a criteria query, the org.hibernate.criterion.InExpression class should split the expression into several smaller ones.
> Attached is a patch which splits the expression by slices of 500 elements. For example, if we have 1001 elements to put in the "in" expression, the result would be :
> (entity.field in (?, ?, ?...) or entity.field in (?, ?, ?...) or entity.field in (?))
> The surrounding parantheses are useful to avoid problems with other conditions (a "and" condition taking over the one of the "or" conditions).

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list