Uploaded image for project: 'z - Hibernate 2'
  1. HB-517

Expression.in(String, Collection) doesn't check Collection.size()==0 automatically

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1 rc1
    • Fix Version/s: 2.1 final
    • Component/s: None
    • Labels:
      None
    • Environment:
      w2k, jdk1.4
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true

      Description

      I used Expression.in(column:String, inValue:Collection) to add query condition. As for argument Collection it is a dnynamic List. When inValue.size()==0 I do not want Expression add condition string like xxxColumn in .Now when inValue.size()==0 Hibernate2 throws Exception when Criteria.list().
      The fragment of my code is the following.

      Criteria crit = session.createCriteria(WsStockPriceModel.class);

      crit.add(
      Expression.between(
      "pubDate",
      model.getSearchBeginDate(),
      model.getSearchEndDate()));
      crit.add(Expression.in("productName",
      model.getSearchProductNames()));
      crit.setFirstResult(firstResult);
      crit.setMaxResults(pageSize);

      List list = crit.list();

      And the fragment of Exception is the following.
      java.lang.NegativeArraySizeException

      at java.lang.StringBuffer.<init>(StringBuffer.java:115)

      at net.sf.hibernate.util.StringHelper.repeat(StringHelper.java:47)

      at net.sf.hibernate.expression.InExpression.toSqlString(InExpression.java:26)

      at net.sf.hibernate.loader.CriteriaLoader.<init>(CriteriaLoader.java:61)

      at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3430)

      at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:177)
      ...............................

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: