Skip to content

Fix to check for empty criteria #1338

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
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* @author Mikhail Polivakha
* @author Chirag Tailor
* @author Diego Krupitza
* @author Hari Ohm Prasath
*/
class SqlGenerator {

Expand Down Expand Up @@ -941,7 +942,7 @@ private SelectBuilder.SelectOrdered applyQueryOnSelect(Query query, MapSqlParame
SelectBuilder.SelectOrdered applyCriteria(@Nullable CriteriaDefinition criteria,
SelectBuilder.SelectWhere whereBuilder, MapSqlParameterSource parameterSource, Table table) {

return criteria != null //
return criteria != null && !criteria.isEmpty() // Check for null and empty criteria
? whereBuilder.where(queryMapper.getMappedObject(parameterSource, criteria, table, entity)) //
: whereBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
* @author Mikhail Polivakha
* @author Chirag Tailor
* @author Diego Krupitza
* @author Hari Ohm Prasath
*/
@SuppressWarnings("Convert2MethodRef")
class SqlGeneratorUnitTests {
Expand Down Expand Up @@ -779,6 +780,15 @@ void selectByQueryValidTest() {
.containsOnly(entry("x_name", probe.name));
}

@Test // GH-1329
void selectWithOutAnyCriteriaTest() {
SqlGenerator sqlGenerator = createSqlGenerator(DummyEntity.class);
Query query = Query.query(Criteria.empty());
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
String generatedSQL = sqlGenerator.selectByQuery(query, parameterSource);
assertThat(generatedSQL).isNotNull().doesNotContain("where");
}

@Test // GH-1192
void existsByQuerySimpleValidTest() {

Expand Down