Skip to content

Allow foreignKey element in <entityTable> of a <joinedHierarchy> to be optional #15

@upachler

Description

@upachler

Currently, the foreignKey attribute in a <joinedHierarchy> is mandatory. Consider this example:

<mappingConfig ...>

    <entityTable table="LIFEFORM">
        <joinedHierarchy>
            <rootEntity discriminatorColumn='KIND' discriminator='LF'/>
            <entityTable table="MAMMAL" discriminator="MA" foreignKey="FK_MAMMAL_LIFEFORM"/>
            <entityTable table="INSECT" discriminator="IN" foreignKey="FK_INSECT_LIFEFORM"/>
        </joinedHierarchy>
    </entityTable>

</mappingConfig>

However, in most cases we can determine which foreign key to use for an <entityTable> automatically: We only need to look for the foreign referring to the root table. The only time we need a distinction is when a table has more than one foreign key referring to the root table and the default does not suffice.

The proposal:

  • if foreignKey is specified, it determines the foreign key to use for joins with the root table
  • If foreignKey is absent, derive the foreign key like this:
    • iterate over all foreign keys
    • stop iteration at the first foreign key which refers to the root table and use that
    • if no foreign key is found, it is an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions