Nested embeddable entities and AttributeOverrides for all levels

When using nested embeddable entities, the @AttributeOverrides are not used for the attributes in the nested entities. This results in overridden columns in DB when more than one nested embeddable entity of the same type is used.

Test project:
nested_embeddable.zip (105.7 KB)

The resulting Liquibase is:

<createTable tableName="TEST_ENTITY">
    <column name="EMBEDDED_ATTRIBUTE1_FIRST_LEVEL_ATTRIBUTE" type="VARCHAR(255)"/>
    <column name="FIRST_LEVEL_EMBEDDED_ATTRIBUTE_SECOND_LEVEL_ATTRIBUTE" type="VARCHAR(255)"/>
    <column name="EMBEDDED_ATTRIBUTE2_FIRST_LEVEL_ATTRIBUTE" type="VARCHAR(255)"/>
</createTable>

Expected would be (I added prefixes for all nested levels):

<createTable tableName="TEST_ENTITY">
    <column name="EMBEDDED_ATTRIBUTE1_FIRST_LEVEL_ATTRIBUTE" type="VARCHAR(255)"/>
    <column name="EMBEDDED_ATTRIBUTE1_FIRST_LEVEL_EMBEDDED_ATTRIBUTE_SECOND_LEVEL_ATTRIBUTE" type="VARCHAR(255)"/>
    <column name="EMBEDDED_ATTRIBUTE2_FIRST_LEVEL_ATTRIBUTE" type="VARCHAR(255)"/>
    <column name="EMBEDDED_ATTRIBUTE2_FIRST_LEVEL_EMBEDDED_ATTRIBUTE_SECOND_LEVEL_ATTRIBUTE" type="VARCHAR(255)"/>
</createTable>

EMBEDDED_ATTRIBUTE1_ and EMBEDDED_ATTRIBUTE2_ were added to the 3rd and 5th column. The 5th column is new.

Even if I manually add @AttributeOverride for the 2nd level (see below) it doesn’t produce the wished-for Liquibase:

    @EmbeddedParameters(nullAllowed = false)
    @Embedded
    @AttributeOverrides({
            @AttributeOverride(name = "firstLevelAttribute", column = @Column(name = "EMBEDDED_ATTRIBUTE1_FIRST_LEVEL_ATTRIBUTE")),

            // This is the missing @AttributeOverride for the 2nd level attribute.
            @AttributeOverride(name = "secondLevelAttribute", column = @Column(name = "EMBEDDED_ATTRIBUTE1_FIRST_LEVEL_EMBEDDED_ATTRIBUTE_SECOND_LEVEL_ATTRIBUTE"))
    })
    private FirstLevelEmbeddable embeddedAttribute1;

    @EmbeddedParameters(nullAllowed = false)
    @Embedded
    @AttributeOverrides({
            @AttributeOverride(name = "firstLevelAttribute", column = @Column(name = "EMBEDDED_ATTRIBUTE2_FIRST_LEVEL_ATTRIBUTE")),

            // This is the missing @AttributeOverride for the 2nd level attribute.
            @AttributeOverride(name = "secondLevelAttribute", column = @Column(name = "EMBEDDED_ATTRIBUTE2_FIRST_LEVEL_EMBEDDED_ATTRIBUTE_SECOND_LEVEL_ATTRIBUTE"))
    })
    private FirstLevelEmbeddable embeddedAttribute2;

@AssociationOverrides should also add prefixes for all nested levels.

Is it possible to support using @AttributeOverride and @AssociationOverride for nested embedded entities if they are present as in the code above (see both @AttributeOverride(name = "secondLevelAttribute")?


Jmix version: 2.5.0
Jmix Studio Plugin Version: 2.5.0-243
IntelliJ version: IntelliJ IDEA 2024.3.4.1 (Community Edition)

Hi,

Thank you for report the problem.
I have created an issue.

Regards,
Mikhail

1 Like

I’ve done more development using nested embeddable and found out that Jmix Studio is not only ignoring @AttributeOverride for nested attributes, but it is actually deleting them when added by hand.

Updated test project:
nested_embeddable2.zip (105.7 KB)

Manually added @AttributeOverride for the 2nd level in the TestEntity class are removed by Jmix Studio when entity designer is used to add another attribute.

How to reproduce it in the attached project:

  • open TestEntity

  • switch to Designer

  • add attribute (e.g. Name: test, click OK)

  • switch to Text

  • the below two lines were deleted by Jmix Studio (below the // This is the missing @AttributeOverride...):

    • @AttributeOverride(name = “firstLevelEmbeddedAttribute.secondLevelAttribute”, column = @Column(name = “EMBEDDED_ATTRIBUTE1_FIRST_LEVEL_EMBEDDED_ATTRIBUTE_SECOND_LEVEL_ATTRIBUTE”))
    • @AttributeOverride(name = “firstLevelEmbeddedAttribute.secondLevelAttribute”, column = @Column(name = “EMBEDDED_ATTRIBUTE2_FIRST_LEVEL_EMBEDDED_ATTRIBUTE_SECOND_LEVEL_ATTRIBUTE”))

This removal can be overlooked if the manually added lines were not yet committed to git and don’t show in the diff of the next commit.

Even more concerning is that using a Design view on one entity removes the added lines in other entities. Commit diff is again the only way to realize the lines were removed since you don’t check the source code of all related entities.

Can this issue be marked as a bug in YouTrack and get assigned to somebody? :pray:


Jmix version: 2.5.1
Jmix Studio Plugin Version: 2.5.1-243
IntelliJ version: IntelliJ IDEA 2024.3.5 (Community Edition)