Created
February 26, 2013 11:01
-
-
Save jarek-przygodzki/5037680 to your computer and use it in GitHub Desktop.
HOW to Handle ORA-01795 in Hibernate using Restrictions.disjunction()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://docs.jboss.org/hibernate/core/3.3/api/org/hibernate/criterion/Restrictions.html#disjunction%28%29 | |
public static Criterion createInRestriction(String propertyName, Collection values) { | |
if (values.size() <= 1000) { | |
return Restrictions.in(propertyName, values); | |
} else { | |
List valueList = asList(values); | |
Disjunction disjunction = Restrictions.disjunction(); | |
int packSize = 1000; | |
for (int i = 0; i < values.size(); i += pack) { | |
int end = Math.min(i + pack, values.size()); | |
List subList = valueList.subList(i, end); | |
disjunction.add(Restrictions.in(propertyName, subList)); | |
} | |
return disjunction; | |
} | |
} | |
private static List asList(Collection c) { | |
List valuesList ; | |
if (c instanceof List) { | |
valueList = (List) values; | |
} else { | |
valueList = new ArrayList(values); | |
} | |
return valuesList; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment