Hibernate Criterion IN第1000条分手

sha*_*eef 12 java hibernate database-performance

嗨,我有这个大型的oracle hibernate Web应用程序,它似乎给出了这个错误

ORA-01795: maximum number of expressions in a list is 1000

我需要一个由某人测试的java代码作为一个hibernate用户定义的组件,在我的屏幕中添加到我的搜索java类,尽可能容易有人有这样的测试组件?

sha*_*eef 23

我尝试了以下代码来自链接,它似乎工作得很漂亮我将粘贴代码,以防万一将来链接被破坏.

保持简单保持微笑:)

    /**
    * 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;
    }
}
Run Code Online (Sandbox Code Playgroud)