Saturday, August 8, 2009

Where Oracle IN operator fails...

I figured this out while working in one of my recent projects. Implementing the data access layer for search use cases through Spring's Hibernate support framework, I require to create a lot of restrictions (Hibernate Criterion API). This most of the time requires to create a Restrictions.sqlRestriction criterion for certain search criteria. I had a condition to create a restriction like this

DetachedCriteria criteria = DetachedCriteria.forClass(Client.class);

criteria.add(Restrictions.in("clientId",getClientIds()) );

I created a seperate method getClientIds which gives back a list of clientIds. The problem occured when the number of clientIds returned by getClientIds method is more than 1000. IN operator against oracle fails with an exception if the number of items in the IN operator is > 1000. I got over this problem by replacing the clientId IN (id1, id2, id3,...id1000) kind of clause by clientId IN (innerQuery).

No comments:

Post a Comment