Problem with entity of tree

I create tree with entity reference itself

@JoinColumn(name = "parent_code", referencedColumnName = "code")
    @ManyToOne(fetch = FetchType.LAZY)
    private CategoryActionTree parentCategory;

and code is not id.
It throws exception

java.lang.IllegalArgumentException: CATEG111
	at io.jmix.core.UuidProvider.fromString(UuidProvider.java:58) ~[jmix-core-1.2.4.jar:na]
	at io.jmix.eclipselink.impl.lazyloading.SingleValueOwningPropertyHolder.convertId(SingleValueOwningPropertyHolder.java:73) ~[jmix-eclipselink-1.2.4.jar:na]
	at io.jmix.eclipselink.impl.lazyloading.SingleValueOwningPropertyHolder.getEntityId(SingleValueOwningPropertyHolder.java:48) ~[jmix-eclipselink-1.2.4.jar:na]

How can i resolve this problem

2 Likes

Hello Tien Vu,
Thank you for reporting! This problem caused by incorrect liquibase script generation. I’ve created the issue: https://youtrack.jmix.io/issue/JST-3183.

As workaround liquibase scripts can be fixed manually to look like:

 <createTable tableName="CATEGORY_ACTION_TREE">
            <column name="ID" type="UUID">
                <constraints nullable="false" primaryKey="true" primaryKeyName="PK_CATEGORY_ACTION_TREE"/>
            </column>
            <column name="CODE" type="VARCHAR(255)">
                <constraints nullable="false" unique="true"/>
            </column>
            <column name="TITLE" type="VARCHAR(255)"/>
            <column name="parent_code" type="VARCHAR(255)"/>
        </createTable>
<!-- ... -->
        <addForeignKeyConstraint baseColumnNames="parent_code" baseTableName="CATEGORY_ACTION_TREE"
                                 constraintName="FK_CATEGORYACTIO_ON_PARENTCODE" referencedColumnNames="CODE"
                                 referencedTableName="CATEGORY_ACTION_TREE"/>
  • code column should have unique constraint
  • parent_code should have correct type
  • constraint should have correct value in referenceColumnNames

Database should be recreated if this changes applied to existing scripts.
After that just ignore liquibase changes from studio for these columns and constraints.

Regards,
Dmitry