问题描述
您好,我有这个大的oracle hibernate web应用程序,它似乎给这个错误
ORA-01795:表达式的最大数目列表是1000
我需要一个由某人测试的java代码作为一个hibernate用户定义的组件添加到我的屏幕中的我的搜索java类尽可能容易有人有这样的测试组件?
我尝试了下面的代码,它似乎工作得很好,我会粘贴代码以防链接在将来被破坏。
保持简单保持微笑:)
*如果传递的参数
*值的数量大于1000,则构建Criterion Query IN子句的实用程序方法。Oracle不允许超过
* 1000参数值IN子句。这样做{@link SQLException}是带有错误代码的'
*','ORA-01795:列表中最大表达式数量为1000'。
* @param propertyName
* @param values
* @return
* /
import java.util.List;
import org.hibernate.criterion.Restrictions;
/ **
*
* @author 2796
* /
public class SplitHibernateIn {
private static int PARAMETER_LIMIT = 999;
public static org.hibernate.criterion.Criterion buildInCriterion(String propertyName,List values){
org.hibernate.criterion.Criterion criterion = null;
int listSize = values.size();
for(int i = 0; i< listSize; i + = PARAMETER_LIMIT){
List subList; (listSize> i + PARAMETER_LIMIT){
subList = values.subList(i,(i + PARAMETER_LIMIT));
} else {
subList = values.subList(i,listSize); (标准!=空){
标准=限制。或(标准,限制.in(propertyName,subList));
}
。
} else {
criterion = Restrictions.in(propertyName,subList);
}
}
返回标准;
}
}
Hi i have this large oracle hibernate web applications and it seems to give this error
ORA-01795: maximum number of expressions in a list is 1000
and i need a java code tested by someone as a hibernate user defined component to add to my search java classes in my screen as easy as possible could someone have such tested component?
i tried this below code from link and it seem to work beautifully i will paste the code in-case the link were broken in future.
Keep it Simple Keep it Smile :)
/**
* An utility method to build the Criterion Query IN clause if the number of parameter
* values passed has a size more than 1000. Oracle does not allow more than
* 1000 parameter values in a IN clause. Doing so a {@link SQLException} is
* thrown with error code, 'ORA-01795: maximum number of expressions in a list is 1000'.
* @param propertyName
* @param values
* @return
*/
import java.util.List;
import org.hibernate.criterion.Restrictions;
/**
*
* @author 2796
*/
public class SplitHibernateIn {
private static int PARAMETER_LIMIT = 999;
public static org.hibernate.criterion.Criterion buildInCriterion(String propertyName, List values) {
org.hibernate.criterion.Criterion criterion = null;
int listSize = values.size();
for (int i = 0; i < listSize; i += PARAMETER_LIMIT) {
List subList;
if (listSize > i + PARAMETER_LIMIT) {
subList = values.subList(i, (i + PARAMETER_LIMIT));
} else {
subList = values.subList(i, listSize);
}
if (criterion != null) {
criterion = Restrictions.or(criterion, Restrictions.in(propertyName, subList));
} else {
criterion = Restrictions.in(propertyName, subList);
}
}
return criterion;
}
}
这篇关于Hibernate Criterion IN子句1000分手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!