Skip to content

Commit 256cc0d

Browse files
committed
New default behaviour for back reference naming.
The new default is to take `@Table` annotations into account. The behaviour can be configured by setting the `foreignKeyNaming` property on the `RelationalMappingContext`. Closes #1162 See #1147
1 parent 793bcb6 commit 256cc0d

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void cascadingDeleteAllSecondLevel() {
134134

135135
assertThat(sql)
136136
.isEqualTo("DELETE FROM \"FIXEDCUSTOMSCHEMA\".\"FIXEDCUSTOMTABLEPREFIX_SECONDLEVELREFERENCEDENTITY\" "
137-
+ "WHERE \"FIXEDCUSTOMSCHEMA\".\"FIXEDCUSTOMTABLEPREFIX_SECONDLEVELREFERENCEDENTITY\".\"REFERENCED_ENTITY\" IN "
137+
+ "WHERE \"FIXEDCUSTOMSCHEMA\".\"FIXEDCUSTOMTABLEPREFIX_SECONDLEVELREFERENCEDENTITY\".\"FIXEDCUSTOMTABLEPREFIX_REFERENCEDENTITY\" IN "
138138
+ "(SELECT \"FIXEDCUSTOMSCHEMA\".\"FIXEDCUSTOMTABLEPREFIX_REFERENCEDENTITY\".\"FIXEDCUSTOMPROPERTYPREFIX_L1ID\" "
139139
+ "FROM \"FIXEDCUSTOMSCHEMA\".\"FIXEDCUSTOMTABLEPREFIX_REFERENCEDENTITY\" "
140140
+ "WHERE \"FIXEDCUSTOMSCHEMA\".\"FIXEDCUSTOMTABLEPREFIX_REFERENCEDENTITY\".\"DUMMY_ENTITY\" = :rootId)");
@@ -170,7 +170,7 @@ public void cascadingDeleteSecondLevel() {
170170

171171
assertThat(sql)
172172
.isEqualTo("DELETE FROM \"FIXEDCUSTOMSCHEMA\".\"FIXEDCUSTOMTABLEPREFIX_SECONDLEVELREFERENCEDENTITY\" "
173-
+ "WHERE \"FIXEDCUSTOMSCHEMA\".\"FIXEDCUSTOMTABLEPREFIX_SECONDLEVELREFERENCEDENTITY\".\"REFERENCED_ENTITY\" IN "
173+
+ "WHERE \"FIXEDCUSTOMSCHEMA\".\"FIXEDCUSTOMTABLEPREFIX_SECONDLEVELREFERENCEDENTITY\".\"FIXEDCUSTOMTABLEPREFIX_REFERENCEDENTITY\" IN "
174174
+ "(SELECT \"FIXEDCUSTOMSCHEMA\".\"FIXEDCUSTOMTABLEPREFIX_REFERENCEDENTITY\".\"FIXEDCUSTOMPROPERTYPREFIX_L1ID\" "
175175
+ "FROM \"FIXEDCUSTOMSCHEMA\".\"FIXEDCUSTOMTABLEPREFIX_REFERENCEDENTITY\" "
176176
+ "WHERE \"FIXEDCUSTOMSCHEMA\".\"FIXEDCUSTOMTABLEPREFIX_REFERENCEDENTITY\".\"DUMMY_ENTITY\" IS NOT NULL)");

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/PartTreeJdbcQueryUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class PartTreeJdbcQueryUnitTests {
6767

6868
private static final String TABLE = "\"users\"";
6969
private static final String ALL_FIELDS = "\"users\".\"ID\" AS \"ID\", \"users\".\"AGE\" AS \"AGE\", \"users\".\"ACTIVE\" AS \"ACTIVE\", \"users\".\"LAST_NAME\" AS \"LAST_NAME\", \"users\".\"FIRST_NAME\" AS \"FIRST_NAME\", \"users\".\"DATE_OF_BIRTH\" AS \"DATE_OF_BIRTH\", \"users\".\"HOBBY_REFERENCE\" AS \"HOBBY_REFERENCE\", \"hated\".\"NAME\" AS \"HATED_NAME\", \"users\".\"USER_CITY\" AS \"USER_CITY\", \"users\".\"USER_STREET\" AS \"USER_STREET\"";
70-
private static final String JOIN_CLAUSE = "FROM \"users\" LEFT OUTER JOIN \"HOBBY\" \"hated\" ON \"hated\".\"USER\" = \"users\".\"ID\"";
70+
private static final String JOIN_CLAUSE = "FROM \"users\" LEFT OUTER JOIN \"HOBBY\" \"hated\" ON \"hated\".\"USERS\" = \"users\".\"ID\"";
7171
private static final String BASE_SELECT = "SELECT " + ALL_FIELDS + " " + JOIN_CLAUSE;
7272

7373
JdbcMappingContext mappingContext = new JdbcMappingContext();

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/DefaultNamingStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class DefaultNamingStrategy implements NamingStrategy {
3232
*/
3333
public static NamingStrategy INSTANCE = new DefaultNamingStrategy();
3434

35-
private ForeignKeyNaming foreignKeyNaming = ForeignKeyNaming.IGNORE_RENAMING;
35+
private ForeignKeyNaming foreignKeyNaming = ForeignKeyNaming.APPLY_RENAMING;
3636

3737
@Override
3838
public void setForeignKeyNaming(ForeignKeyNaming foreignKeyNaming) {

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class RelationalMappingContext
3636

3737
private final NamingStrategy namingStrategy;
3838
private boolean forceQuote = true;
39-
private ForeignKeyNaming foreignKeyNaming = ForeignKeyNaming.IGNORE_RENAMING;
39+
private ForeignKeyNaming foreignKeyNaming = ForeignKeyNaming.APPLY_RENAMING;
4040

4141
/**
4242
* Creates a new {@link RelationalMappingContext}.

src/main/asciidoc/jdbc.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ Also, the type of that aggregate is encoded in a type parameter.
249249
==== Back References
250250

251251
All references in an aggregate result in a foreign key relationship in the opposite direction in the database.
252-
By default, the name of the foreign key column is the table name of the referencing entity, ignoring any table annotations.
252+
By default, the name of the foreign key column is the table name of the referencing entity.
253253

254-
Alternatively you may choose to have them named by the actual table name of the referencing entity.
255-
You activate this behaviour by calling `setForeignKeyNaming(ForeignKeyNaming.APPLY_RENAMING)` on the `RelationalMappingContext`.
254+
Alternatively you may choose to have them named by the entity name of the referencing entity ignoreing `@Table` annotations.
255+
You activate this behaviour by calling `setForeignKeyNaming(ForeignKeyNaming.IGNORE_RENAMING)` on the `RelationalMappingContext`.
256256

257257
For `List` and `Map` references an additional column is required for holding the list index or map key. It is based on the foreign key column with an additional `_KEY` suffix.
258258

0 commit comments

Comments
 (0)