spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
3.03k stars 1.43k forks source link

Update JPQL and HQL parsers with newly introduced JPA 3.2 keywords #3136

Open mp911de opened 1 year ago

mp911de commented 1 year ago

See https://deploy-preview-652--jakartaee-specifications.netlify.app/specifications/persistence/3.2/

Nendanfito commented 6 months ago

Does null precedence work on Page requests? Because its not working for me with version 3.2.1

Sort.Order sort = switch (direction != null ? direction : "") {
            case "asc" -> Sort.Order.asc(sortBy);
            case "desc" -> Sort.Order.desc(sortBy).nullsLast();
            default -> Sort.Order.asc("code");
        };

PageRequest pageRequest = PageRequest.of(
                alarmPageableFilter.getPageNumber(),
                alarmPageableFilter.getPageSize(),
                Sort.by(sort));

Page<Alarm> page = alarmRepository.findAll(getByFilter(alarmPageableFilter), pageRequest);
mp911de commented 6 months ago

No, it's not working with 3.2.1 because the JPA spec level is at 3.1. Starting with JPA 3.2, the API will specify null precedence (see https://projects.eclipse.org/projects/ee4j.jpa/releases/3.2)

ducanh2110 commented 5 months ago

I have the same issue too. Dont understand why it's happen

joseardaiz commented 5 months ago

@mp911de and @christophstrobl - would you guys know when the issue that @Nendanfito explained here will be fixed?

emaranga commented 4 weeks ago

Does null precedence work on Page requests? Because its not working for me with version 3.2.1

Sort.Order sort = switch (direction != null ? direction : "") {
            case "asc" -> Sort.Order.asc(sortBy);
            case "desc" -> Sort.Order.desc(sortBy).nullsLast();
            default -> Sort.Order.asc("code");
        };

PageRequest pageRequest = PageRequest.of(
                alarmPageableFilter.getPageNumber(),
                alarmPageableFilter.getPageSize(),
                Sort.by(sort));

Page<Alarm> page = alarmRepository.findAll(getByFilter(alarmPageableFilter), pageRequest);

Did you find a workaround?

Nendanfito commented 4 weeks ago

@emaranga I configured it for spring in general in the application.yaml:

spring:
  jpa:
    properties:
      hibernate:
        order_by:
          default_null_ordering: last

With that solution all the querys made by jpa will return nulls last, in case you don't want it you have to made a nativeQuery.