You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Will Dazey (Jira)" <ji...@apache.org> on 2022/03/15 18:32:00 UTC

[jira] [Created] (OPENJPA-2901) Regression in CriteriaBuilder ParameterExpression behavior

Will Dazey created OPENJPA-2901:
-----------------------------------

             Summary: Regression in CriteriaBuilder ParameterExpression behavior
                 Key: OPENJPA-2901
                 URL: https://issues.apache.org/jira/browse/OPENJPA-2901
             Project: OpenJPA
          Issue Type: Bug
    Affects Versions: 3.1.2, 3.0.0
            Reporter: Will Dazey


I was testing OpenJPA for CriteriaBuilder and I noticed a regression in behavior when setting ParameterExpressions

Entity:
```
@Entity
public class SimpleEntity {

    @Id @Column(name = "KEY_CHAR")
    private String KeyString;

    @Column(name = "ITEM_STRING1")
    private String itemString1;

    @Column(name = "ITEM_STRING2")
    private String itemString2;

    @Column(name = "ITEM_STRING3")
    private String itemString3;

    @Column(name = "ITEM_STRING4")
    private String itemString4;

    @Column(name = "ITEM_INTEGER1")
    private Integer itemInteger1;
```

Test:
```
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<SimpleEntity> cquery = cb.createQuery(SimpleEntity.class);
    Root<SimpleEntity> root = cquery.from(SimpleEntity.class);
    cquery.select(root);

    ParameterExpression<String> strValue1 = cb.parameter(String.class);
    ParameterExpression<String> strValue2 = cb.parameter(String.class);
    ParameterExpression<String> strValue3 = cb.parameter(String.class);
    ParameterExpression<String> strValue4 = cb.parameter(String.class);
    cquery.where(root.get(SimpleEntity_.itemString1).in(strValue1, strValue2, strValue3, strValue4));

    query = em.createQuery(cquery);
    query.setParameter(strValue1, "HELLO");
    query.setParameter(strValue2, "ONE");
    query.setParameter(strValue3, "WORLD");
    query.setParameter(strValue4, "PEOPLE");
```

3.0.0 SQL Trace:
```
openjpa.jdbc.SQL - <t 856624410, conn 2130397255> executing prepstmnt 1876167186 
SELECT t0.KEY_CHAR, t0.ITEM_INTEGER1, t0.ITEM_STRING1, t0.ITEM_STRING2, 
        t0.ITEM_STRING3, t0.ITEM_STRING4 
    FROM SimpleEntity t0 
    WHERE ((t0.ITEM_STRING1 = ? OR t0.ITEM_STRING1 = ? OR t0.ITEM_STRING1 = 
        ? OR t0.ITEM_STRING1 = ?) AND t0.ITEM_STRING1 IS NOT NULL) 
[params=(String) HELLO, (String) ONE, (String) WORLD, (String) PEOPLE]
```

3.1.2 SQL Trace:
```
openjpa.jdbc.SQL - <t 613066919, conn 661502036> executing prepstmnt 1987058658 
SELECT t0.KEY_CHAR, t0.ITEM_INTEGER1, t0.ITEM_STRING1, t0.ITEM_STRING2, 
        t0.ITEM_STRING3, t0.ITEM_STRING4 
    FROM SimpleEntity t0 
    WHERE ((t0.ITEM_STRING1 = ? OR t0.ITEM_STRING1 = ? OR t0.ITEM_STRING1 = 
        ? OR t0.ITEM_STRING1 = ?) AND t0.ITEM_STRING1 IS NOT NULL) 
[params=(String) HELLO, (String) HELLO, (String) HELLO, (String) HELLO]
```

I have not tested against the latest 3.2.1 binary yet, so I don't know if this was fixed in the latest 3.2.x, but the latest 3.1.x does contain this issue. I will test 3.2.x next.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)