Browse Source

Improved error message on missing back reference.

Closes #833
Original pull request 1384
pull/1396/head
Viktor Ardelean 3 years ago committed by Jens Schauder
parent
commit
09f9da5128
No known key found for this signature in database
GPG Key ID: 9537B67540F0A581
  1. 5
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java
  2. 11
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlGeneratorUnitTests.java

5
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java

@ -260,7 +260,10 @@ class SqlGenerator { @@ -260,7 +260,10 @@ class SqlGenerator {
Condition condition = null;
for (SqlIdentifier backReferenceColumn : parentIdentifier.toMap().keySet()) {
if (SqlIdentifier.EMPTY.equals(backReferenceColumn)){
throw new UnsupportedOperationException(
"An empty SqlIdentifier can't be used in condition. Make sure that all composite primary keys are defined in the query.");
}
Condition newCondition = table.column(backReferenceColumn).isEqualTo(getBindMarker(backReferenceColumn));
condition = condition == null ? newCondition : condition.and(newCondition);
}

11
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlGeneratorUnitTests.java

@ -443,6 +443,17 @@ class SqlGeneratorUnitTests { @@ -443,6 +443,17 @@ class SqlGeneratorUnitTests {
}
@Test // DATAJDBC-613
void findAllByPropertyWithEmptyBackrefColumn() {
assertThatThrownBy(() -> {
sqlGenerator.getFindAllByProperty(Identifier.of(EMPTY, 0, Object.class),
unquoted("key-column"),
false);
}).isInstanceOf(UnsupportedOperationException.class)
.hasMessageContaining("An empty SqlIdentifier can't be used in condition. Make sure that all composite primary keys are defined in the query.");
}
@Test // DATAJDBC-219
void updateWithVersion() {

Loading…
Cancel
Save