Uploaded image for project: 'Spring Data JPA'
  1. Spring Data JPA
  2. DATAJPA-1163

spring-data fails when #{#entityName} SpEL is using in countQuery definition

    Details

      Description

      see example here: https://github.com/daggerok/spring-data-spel-example/blob/master/app/src/main/java/daggerok/domain/MyEntityRepository.java

      if I'm using #entityName SpEL inside @Query.value all works fine with MyEntity in @Query.countQuery:

        @Query(
            value = " select me.name from #{#entityName} me ",
            countQuery = " select count(me.id) from MyEntity me "
        )
        Page<String> findAllNames(final Pageable pageable);
      

      but if I try use same #entityName SpEL inside @Query.countQuery, just like so:

        @Query(
            value = " select me.name from #{#entityName} me ",
            countQuery = " select count(me.id) from #{#entityName} me "
        )
        Page<String> findAllNames(final Pageable pageable);
      

      application fails:

      ...
      Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: unexpected char: '#' [ select count(me.id) from #{#entityName} me ]
      ...
      Caused by: org.hibernate.QueryException: unexpected char: '#' [ select count(me.id) from #{#entityName} me ]
      ...
      

      what the different betweel value and countQuery and why we can use same SpEL in both?

      links:


      Regards,
      Maksim

        Attachments

          Activity

            People

            • Assignee:
              schauder Jens Schauder
              Reporter:
              daggerok Maksim Kostromin
              Last updater:
              Mark Paluch
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: