vohoaiviet / hibernate-generic-dao

Automatically exported from code.google.com/p/hibernate-generic-dao
0 stars 0 forks source link

Version 1.1.3 InExpression can not handle values not null but without any elements #104

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
NOTE: If you have a question rather than a bug report or feature request,
please post at http://groups.google.com/group/java-generic-dao .

What steps will reproduce the problem?
1. In the case I want do an in query
2. I find a list of elements in some time this list may not contains any element
3. I use the Restrictions.in(property, list)

What is the expected output? What do you see instead?
the expected result may something like this Entity.property in ()
but the result is Entity.property in )

What version of the product are you using? On what operating system?
Version 1.1.3

Please provide any additional information below.
    public String toSqlString(Criteria criteria, Criteria.CriteriaQuery criteriaQuery) {
        String sql = criteriaQuery.getPropertyName(property, criteria) + " in ( ";

        for (Object v : values) {
            criteriaQuery.setParam(v);
            sql += "?,";
        }

        return sql.substring(0, sql.length() - 1) + ")";
    }

the return statement not consider the case values.length < 1
the easyest way to solve this problem is add a space after the "in ( "

Original issue reported on code.google.com by jackydu1...@gmail.com on 19 Jun 2013 at 6:29