Avoid unnecessary joins.

Original pull request #980
This commit is contained in:
Jens Schauder
2021-05-18 14:41:11 +02:00
parent f08b5cae6f
commit b99b4aaf2d
2 changed files with 9 additions and 7 deletions

View File

@@ -241,12 +241,6 @@ class JdbcQueryCreator extends RelationalQueryCreator<ParametrizedQuery> {
PersistentPropertyPathExtension extPath = new PersistentPropertyPathExtension(context, path);
// add a join if necessary
Join join = getJoin(sqlContext, extPath);
if (join != null) {
joinTables.add(join);
}
if (returnedType.needsCustomConstruction()) {
if (!returnedType.getInputProperties()
.contains(extPath.getRequiredPersistentPropertyPath().getBaseProperty().getName())) {
@@ -254,6 +248,12 @@ class JdbcQueryCreator extends RelationalQueryCreator<ParametrizedQuery> {
}
}
// add a join if necessary
Join join = getJoin(sqlContext, extPath);
if (join != null) {
joinTables.add(join);
}
Column column = getColumn(sqlContext, extPath);
if (column != null) {
columnExpressions.add(column);

View File

@@ -126,7 +126,7 @@ public class PartTreeJdbcQueryUnitTests {
PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
ParametrizedQuery query = jdbcQuery.createQuery(getAccessor(queryMethod, new Object[] { "John" }), returnedType);
assertThat(query.getQuery()).isEqualTo("SELECT " + TABLE + ".\"FIRST_NAME\" AS \"FIRST_NAME\" " + JOIN_CLAUSE
assertThat(query.getQuery()).isEqualTo("SELECT " + TABLE + ".\"FIRST_NAME\" AS \"FIRST_NAME\" FROM \"users\""
+ " WHERE " + TABLE + ".\"FIRST_NAME\" = :first_name");
}
@@ -601,6 +601,8 @@ public class PartTreeJdbcQueryUnitTests {
List<User> findAllByHated(Hobby hobby);
List<User> findAllByHatedName(String name);
List<User> findAllByHobbies(Object hobbies);
List<User> findAllByHobbyReference(Hobby hobby);