Mapping an existing schema like
create table product(
tenant bigint,
code text,
...
primary key (tenant, code)
);
create table product_i18n(
tenant bigint,
product_code text,
language text,
name text,
description text,
primary key (tenant, product_code, language),
foreign key (tenant, product_code) references product(tenant, code)
);
record ProductPK(Long tenant, String code) {}
@Table("product")
record Product(
@Id ProductPK pk,
@MappedCollection(keyColumn = "language") Map<String, ProductI18n> localization,
...
) {}
@Table("product_i18n")
record ProductI18n(String name, String description) {}
Loading any data expects that the product_i18n.tenant column would be named product_tenant.
Documentation says
All references in an aggregate result in a foreign key relationship in the opposite direction in the database. By default, the name of the foreign key column is the table name of the referencing entity.
If the referenced id is an @Embedded id, the back reference consists of multiple columns, each named by a concatenation of <table-name> + _ + <column-name>. E.g. the back reference to a Person entity, with a composite id with the properties firstName and lastName will consist of the two columns PERSON_FIRST_NAME and PERSON_LAST_NAME.
Alternatively you may choose to have them named by the entity name of the referencing entity ignoring @Table annotations. You activate this behaviour by calling setForeignKeyNaming(ForeignKeyNaming.IGNORE_RENAMING) on the RelationalMappingContext.
I guess the 3rd paragraph is referring to the first and not the second as AggregatePath.java#410 is:
if (idProperty != null && idProperty.isEntity()) {
RelationalPersistentEntity<?> idEntity = basePath.getRequiredLeafEntity();
idEntity.doWithProperties((PropertyHandler<RelationalPersistentProperty>) p -> {
AggregatePath idElementPath = basePath.append(p);
SqlIdentifier name = idElementPath.getColumnInfo().name();
name = name.transform(n -> idDefiningParentPath.getTableInfo().qualifiedTableName.getReference() + "_" + n);
ciBuilder.add(idElementPath, name, name);
});
} else {
so please provide a way to give the name the columns for composite pks back reference.
Have not tested saving, assuming something similar is an issue there.
Mapping an existing schema like
Loading any data expects that the
product_i18n.tenantcolumn would be namedproduct_tenant.Documentation says
I guess the 3rd paragraph is referring to the first and not the second as
AggregatePath.java#410is:so please provide a way to give the name the columns for composite pks back reference.
Have not tested saving, assuming something similar is an issue there.