Skip to content

Cannot map empty Criteria #1329

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

Closed
holmofy opened this issue Sep 17, 2022 · 3 comments
Closed

Cannot map empty Criteria #1329

holmofy opened this issue Sep 17, 2022 · 3 comments
Labels
type: bug A general bug

Comments

@holmofy
Copy link

holmofy commented Sep 17, 2022

spring data jdbc: spring-data-jdbc-3.0.0-M5.jar

controller

@GetMapping
public Page<Issue> index(Issue search, Pageable pageable) {
    return issueDao.findAll(Example.of(search), pageable);
}

request param:
image

This interface doesn't work like spring data jpa's findByExample method. A query with all conditions empty will report an error directly:

java.lang.IllegalArgumentException: Cannot map empty Criteria
	at org.springframework.data.jdbc.core.convert.QueryMapper.getMappedObject(QueryMapper.java:164)
	at org.springframework.data.jdbc.core.convert.SqlGenerator.applyCriteria(SqlGenerator.java:945)
	at org.springframework.data.jdbc.core.convert.SqlGenerator.lambda$applyQueryOnSelect$7(SqlGenerator.java:921)
	at java.base/java.util.Optional.map(Optional.java:260)
	at org.springframework.data.jdbc.core.convert.SqlGenerator.applyQueryOnSelect(SqlGenerator.java:921)
        ...
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 17, 2022
@schauder schauder added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 19, 2022
@hariohmprasath
Copy link
Contributor

hariohmprasath commented Sep 25, 2022

Hi @holmofy,
Looks like the code throws IllegalArgumentException if criteria.isEmpty(), checked part of:

org.springframework.data.jdbc.core.convert.QueryMapper#getMappedObject()

Updating the code according to the attached screenshot should resolve this issue and by if the criteria is empty all the records in the table will be returned falling back to JPA behavior in spring:
Screen Shot 2022-09-25 at 1 34 42 AM

@schauder,
I have created a PR (#1338) with the additional test case to validate this scenario, please let me know your thoughts. Thanks

@holmofy
Copy link
Author

holmofy commented Sep 25, 2022

Yep, that's the problem I'm having. Thank you so much for replying so quickly.

@holmofy holmofy closed this as completed Sep 25, 2022
@schauder
Copy link
Contributor

@holmofy Why did you close this issue? Was your problem resolved? Or was this in anticipation of the PR by @hariohmprasath ? If so, we'll close the issue only after the PR is merged.

Reopening in the assumption the later is the case.

@schauder schauder reopened this Sep 26, 2022
schauder added a commit that referenced this issue Sep 26, 2022
Original pull request #1338
See #1329
@schauder schauder added this to the 3.0 RC1 (2022.0.0) milestone Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants