DATAJDBC-218 - The Column annotation affects the back reference too.
Also: Added documentation for the new behavior. Made the value of the column annotation optional by providing a default. Original pull request: #83.
This commit is contained in:
@@ -131,7 +131,8 @@ You can change this name by implementing `NamingStrategy.getReverseColumnName(Re
|
||||
|
||||
* `Map<simple type, some entity>` is considered a qualified one-to-many relationship.
|
||||
The table of the referenced entity is expected to have two additional columns: One named the same as the table of the referencing entity for the foreign key and one with the same name and an additional `_key` suffix for the map key.
|
||||
You can change this name by implementing `NamingStrategy.getReverseColumnName(RelationalPersistentProperty property)` and `NamingStrategy.getKeyColumn(RelationalPersistentProperty property)`, respectively.
|
||||
You can change this behavior by implementing `NamingStrategy.getReverseColumnName(RelationalPersistentProperty property)` and `NamingStrategy.getKeyColumn(RelationalPersistentProperty property)`, respectively.
|
||||
Alternatively you may annotate the attribute with `@Column(value="your_column_name", keyColumn="your_key_column_name")`
|
||||
|
||||
* `List<some entity>` is mapped as a `Map<Integer, some entity>`.
|
||||
|
||||
|
||||
@@ -73,7 +73,13 @@ class BasicRelationalPersistentProperty extends AnnotationBasedPersistentPropert
|
||||
Assert.notNull(context, "context must not be null.");
|
||||
|
||||
this.context = context;
|
||||
this.columnName = Lazy.of(() -> Optional.ofNullable(findAnnotation(Column.class)).map(Column::value));
|
||||
|
||||
this.columnName = Lazy.of(() -> Optional.ofNullable( //
|
||||
findAnnotation(Column.class)) //
|
||||
.map(Column::value) //
|
||||
.filter(StringUtils::hasText) //
|
||||
);
|
||||
|
||||
this.keyColumnName = Lazy.of(() -> Optional.ofNullable( //
|
||||
findAnnotation(Column.class)) //
|
||||
.map(Column::keyColumn) //
|
||||
@@ -120,7 +126,7 @@ class BasicRelationalPersistentProperty extends AnnotationBasedPersistentPropert
|
||||
|
||||
@Override
|
||||
public String getReverseColumnName() {
|
||||
return context.getNamingStrategy().getReverseColumnName(this);
|
||||
return columnName.get().orElseGet(() -> context.getNamingStrategy().getReverseColumnName(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,7 +35,7 @@ public @interface Column {
|
||||
/**
|
||||
* The mapping column name.
|
||||
*/
|
||||
String value();
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* The column name for key columns of List or Map collections.
|
||||
|
||||
@@ -93,7 +93,7 @@ public class BasicRelationalPersistentPropertyUnitTests {
|
||||
.getRequiredPersistentEntity(DummyEntity.class) //
|
||||
.getRequiredPersistentProperty("someList");
|
||||
|
||||
assertThat(listProperty.getColumnName()).isEqualTo("dummy_column_name");
|
||||
assertThat(listProperty.getReverseColumnName()).isEqualTo("dummy_column_name");
|
||||
assertThat(listProperty.getKeyColumn()).isEqualTo("dummy_key_column_name");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user