Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Data JPA sorting with NullHandling parameter #26172

Closed
nrankovic opened this issue Jun 16, 2022 · 3 comments · Fixed by #26394
Closed

Spring Data JPA sorting with NullHandling parameter #26172

nrankovic opened this issue Jun 16, 2022 · 3 comments · Fixed by #26394
Labels
area/panache area/spring Issues relating to the Spring integration kind/enhancement New feature or request
Milestone

Comments

@nrankovic
Copy link

Describe the bug

While using Spring Data JPA extension and its Sorting and Pageable API, I encountered an issue with NullHandling parameter. It looks like it is ignored while constructing SQL query.

var order = new Sort.Order(Direction.DESC, "modifiedDate", NullHandling.NULLS_LAST);

I would expect NULLS LAST directive to be added before limit in this case. I guess this is something from Spring API that was overlooked, or perhaps I am not using it correctly.

Expected behavior

Constructed SQL query to look something like this:

...
order by
  ticket0_.MODIFIED_DATE DESC NULLS LAST limit ?

Actual behavior

Constructed SQL query looks like this:

...
order by
  ticket0_.MODIFIED_DATE DESC limit ?

How to Reproduce?

No response

Output of uname -a or ver

Darwin my-hostname 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 x86_64

Output of java -version

OpenJDK Runtime Environment Temurin-17.0.3+7 (build 17.0.3+7)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.9.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.6.3

Additional information

No response

@nrankovic nrankovic added the kind/bug Something isn't working label Jun 16, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Jun 16, 2022

/cc @geoand

@quarkus-bot quarkus-bot bot added the area/spring Issues relating to the Spring integration label Jun 16, 2022
@geoand geoand added kind/enhancement New feature or request and removed kind/bug Something isn't working labels Jun 20, 2022
@geoand
Copy link
Contributor

geoand commented Jun 20, 2022

Thanks for reporting!

I'll try and have a look next week

@geoand
Copy link
Contributor

geoand commented Jun 28, 2022

@Sgitario would you be interested in taking a look at this?

Sgitario added a commit to Sgitario/quarkus that referenced this issue Jun 28, 2022
Allow users sorting by either nulls first or nulls last.
Example of usage:

```java
Sort.by("foo", Sort.Direction.Ascending, Sort.NullHandling.NULLS_FIRST);
```

(See more examples in tests)

This PR also adds support of nulls handling for the Spring Data JPA Quarkus extension: it translates the Spring Sort object to the new Panache Sort object. 

Finally, as the Panache Sort API is also used by the Mongo Quarkus extension and Mongo does not easily support sorting by nulls, I decided to simply print a WARNING message if users try to use it.

Fix quarkusio#26172
Sgitario added a commit to Sgitario/quarkus that referenced this issue Jun 28, 2022
Allow users sorting by either nulls first or nulls last.
Example of usage:

```java
Sort.by("foo", Sort.Direction.Ascending, Sort.NullHandling.NULLS_FIRST);
```

(See more examples in tests)

This PR also adds support of nulls handling for the Spring Data JPA Quarkus extension: it translates the Spring Sort object to the new Panache Sort object. 

Finally, as the Panache Sort API is also used by the Mongo Quarkus extension and Mongo does not easily support sorting by nulls, I decided to simply print a WARNING message if users try to use it.

Fix quarkusio#26172
Sgitario added a commit to Sgitario/quarkus that referenced this issue Jul 1, 2022
Allow users sorting by either nulls first or nulls last.
Example of usage:

```java
Sort.by("foo", Sort.Direction.Ascending, Sort.NullHandling.NULLS_FIRST);
```

(See more examples in tests)

This PR also adds support of nulls handling for the Spring Data JPA Quarkus extension: it translates the Spring Sort object to the new Panache Sort object. 

Finally, as the Panache Sort API is also used by the Mongo Quarkus extension and Mongo does not easily support sorting by nulls, I decided to simply print a WARNING message if users try to use it.

Fix quarkusio#26172
Sgitario added a commit to Sgitario/quarkus that referenced this issue Jul 1, 2022
Allow users sorting by either nulls first or nulls last.
Example of usage:

```java
Sort.by("foo", Sort.Direction.Ascending, Sort.NullPrecedence.NULLS_FIRST);
```

(See more examples in tests)

This PR also adds support of nulls handling for the Spring Data JPA Quarkus extension: it translates the Spring Sort object to the new Panache Sort object. 

Finally, as the Panache Sort API is also used by the Mongo Quarkus extension and Mongo does not easily support sorting by nulls, I decided to simply print a WARNING message if users try to use it.

Fix quarkusio#26172
Sgitario added a commit to Sgitario/quarkus that referenced this issue Jul 1, 2022
Allow users sorting by either nulls first or nulls last.
Example of usage:

```java
Sort.by("foo", Sort.Direction.Ascending, Sort.NullPrecedence.NULLS_FIRST);
```

(See more examples in tests)

This PR also adds support of nulls handling for the Spring Data JPA Quarkus extension: it translates the Spring Sort object to the new Panache Sort object. 

Finally, as the Panache Sort API is also used by the Mongo Quarkus extension and Mongo does not easily support sorting by nulls, I decided to simply print a WARNING message if users try to use it.

Fix quarkusio#26172
Sgitario added a commit to Sgitario/quarkus that referenced this issue Jul 1, 2022
Allow users sorting by either nulls first or nulls last.
Example of usage:

```java
Sort.by("foo", Sort.Direction.Ascending, Sort.NullPrecedence.NULLS_FIRST);
```

(See more examples in tests)

This PR also adds support of nulls handling for the Spring Data JPA Quarkus extension: it translates the Spring Sort object to the new Panache Sort object. 

Finally, as the Panache Sort API is also used by the Mongo Quarkus extension and Mongo does not easily support sorting by nulls, I decided to simply print a WARNING message if users try to use it.

Fix quarkusio#26172
@loicmathieu loicmathieu added this to the 2.11 - main milestone Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/panache area/spring Issues relating to the Spring integration kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants