Improved error message on missing back reference.

Closes #833
Original pull request 1384
This commit is contained in:
Viktor Ardelean
2022-11-02 15:38:41 +02:00
committed by Jens Schauder
parent d0a82236c6
commit 09f9da5128
2 changed files with 15 additions and 1 deletions

View File

@@ -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);
}

View File

@@ -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() {