Uploaded image for project: 'Hibernate ORM'
  1. HHH-10729

Issue with CriteriaBuilder.literal(boolean) in my select expression?

    Details

    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      Here is how i build my Select using JPA criteria API, builder bein my CriteriaBuilder

      CriteriaQuery<MyDto> crit = builder.createQuery(MyDto.class).distinct(true);
      Root<MyEntity> root = crit.from(MyEntity.class);
      
      List<Expression<?>> listFields = new ArrayList<>();
      listFields.add(root.get("intField"));
      listFields.add(root.get("stringField"));
      listFields.add(builder.<Boolean> selectCase().when(
              builder.isTrue(root.<Boolean> get("booleanField")), true).otherwise(false));
      listFields.add(builder.literal(false));
      
      Expression[] arraySelect = listFields.toArray(new Expression[listFields.size()]);
      crit.multiselect(arraySelect);
      
      

      And My obj has a constructor :

      public MyDto(Long pIntAttr, String pStringAttr, boolean pBooleanAttr1, boolean pBooleanAttr2) {
          // Build my item
      }
      

      I was using hibernate 4 and had a nullpointer on the handler so after looking in the net, and seeing there was now a BooleanValueHandler in Hibernate 5, I upgraded.

      now the error i get is :

      My title

      Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [mypackage.MyDto]. Expected arguments are: long, java.lang.String, boolean [select distinct new mypackage.MyDto(generatedAlias0.intField, generatedAlias0.stringField, case when generatedAlias1.booleanField = true then true else false end, false) from myEntityPackage.MyEntity as generatedAlias0]

      If i replace the literal(false) by literal(0) and I change the type of pBooleanAttr2 to Integer in the constructor, it works fine.

      If I keep the boolean but remove it from the constructor, it tells me i have 4 fields in my select and only 3 in the constructor.

      So what am I missing ?

      Of course my query is more complex than this.

        Attachments

          Issue links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: