Application components cross-relationship

My question is related the new feature in 6.3 regarding application components. In a large application development this feature is expected to be useful very much. However, it seems it doesn’t work when there is a need to two way relationship of the components.in only 3 components of a business application e.g. accounts, accountsReceivable and inventory components : account profile from accounts component is used in both inventory components and accountsReceivable where as customer from accountsReceivable is used in accounts components. in this case, accounts as component used in accountsReceivable and on the other hand accountsReceivable as component used in accounts – this relationship fails to work. Is this how it is today or I may have some other issue in my testing environment? Thanks for clarifying.

Hi Mortoza,

Two-way relations between app components are impossible since they produce circular dependencies. You should extract the common part of your coarse-grained components to a separate component.

1 Like

Hi Konstantin,
Ok, now I have created a new app component named myutil and re-created the commonly used entities in this app. I still get an exception that looks like it is again falling into circular ref. Here is the relationships between app components.

  1. app: myacct
  • App components: myap, myutil
  1. app: myap
  • App components: myutil
  1. app: myic
  • App components: myap, myutil

In this above relation, notice that myap is a component to myic. Is this supposed to work?

I don’t see circular dependency here, so it should work.

I was hoping so. Therefore, I spent a good amount of time converting my real project and then ending up with the exception. Then created a new component with only one entity and its relation with another entity from one of the two app components similar to the above example then it didn’t work. It works when I remove the component that is consuming another component e.g. if I remove myap component from myacct, it works but i need myap as component too for myacct.

Here is the exception report.


[01:55:20.031] Updating database jdbc:postgresql://localhost/myems and restarting the application server
:accounts-core:assembleDbScripts UP-TO-DATE
:accounts-core:updateDb
:accounts-core:dbScriptsArchive
:accounts-global:compileJavaNote: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

:accounts-global:enhance FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':accounts-global:enhance'.
> Cannot expand ZIP 'D:\Studio Projects\ems\myemsacct\modules\global\build\libs\accounts-global-0.1-SNAPSHOT.jar' as it does not exist.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 8.362 secs
[01:55:30.759] Task 'updateDb, deploy, start' failed
org.gradle.api.InvalidUserDataException: Cannot expand ZIP 'D:\Studio Projects\ems\myemsacct\modules\global\build\libs\accounts-global-0.1-SNAPSHOT.jar' as it does not exist.

OK, we’ll investigate the problem ASAP. Thank you for reporting it.

Hi,

Sometimes, Gradle could not find existent files. It seems the exception occurs by that reason.

Try to restart Gradle daemon by executing the gradle --stop in Terminal or restart the operating system.
Please let us know whether the problem persists.

Even Greadle daemon restarted!

Thanks Konstantin for your investigation and help, Inlook forward.

Hi
Good news is, its now working!
What I have noticed that -

  • when i removed some Entity from one module to another by deleting, the delete function didn’t remove the import reference in the source file.
  • If i remove any app component without deleting the reference entity from that app component, the entries is silently remained in the entity class without showing.
  • if I update any app component, it’s reference entities doesn’t refreshed easily even after assembly. -can we have a refresh button or assembly is the best option?

I am using this app components for many modules and will be back if it see anything else to share for further improvement.

Hi Konstantin
Today I am getting almost similar exceptions and would like to share with you that might help your investigation:

I have several modules (as app components) and some of them are using more than one app components as described below:

  1. module: myap
  • app component used: myutil
  1. module: myic
  • app component used: mutil
  1. module: myar
  • app component used: mutil and myic
  1. module: myacct (accounts)
  • app component used: mutil, myic, myproc, myar

Note there that myar module is using myic (it’s not cross-referenced) but myic is used by this module as well as it is directly used by myacct. myutil is used by all modules though. All of the aboe modules work well except the last one i.e. myacct. Two different kind of behavior I see as follows:

  1. clean works well, Assemble through the following exception:

[20:32:53.505] Updating database jdbc:postgresql://localhost/myems
:accounts-core:assembleDbScripts UP-TO-DATE
:accounts-core:updateDb
Script 70-myar/init/postgres/10.create-db.sql has not been applied, running init scripts
Executing SQL script: D:\Studio Projects\ems\myacct\modules\core\build\db\70-myar\init\postgres\10.create-db.sql
Failed to execute: -- begin MYAR_INVOICE
create table MYAR_INVOICE (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    DTYPE varchar(31),
    --
    DOC_NUMBER bigint,
    DOC_DATE date,
    TOTAL_AMOUNT decimal(19, 2),
    TOTAL_DISCOUNT_AMOUNT decimal(19, 2),
    NET_AMOUNT decimal(19, 2),
    MEMO_AMOUNT decimal(19, 2),
    PAID_AMOUNT decimal(19, 2),
    BALANCE_AMOUNT decimal(19, 2),
    SENT_BY_EMAIL_DATE timestamp,
    CUSTOMER_ID uuid,
    CURRENCY_ID uuid,
    CUSTOMER_PO_NUMBER varchar(255),
    CUSTOMER_PO_DATE date,
    BILL_TO_ADDRESS_ID uuid,
    FINANCIAL_YEAR_ID uuid,
    FINANCIAL_PERIOD_ID uuid,
    DUE_DATE date,
    WAREHOUSE_ID uuid,
    INVOICE_STATUS integer,
    --
    primary key (ID)
) because: ERROR: relation "myar_invoice" already exists
Failed to execute: insert into SYS_DB_CHANGELOG (SCRIPT_NAME, IS_INIT) values (?, ?) because: ERROR: duplicate key value violates unique constraint "sys_db_changelog_pkey"
  Detail: Key (script_name)=(70-myar/update/postgres/16/161209-0-dropCustomerAddress.sql) already exists.

:accounts-core:updateDb FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':accounts-core:updateDb'.
> org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "sys_db_changelog_pkey"
  Detail: Key (script_name)=(70-myar/update/postgres/16/161209-0-dropCustomerAddress.sql) already exists.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.561 secs
[20:32:57.464] Task 'updateDb' failed
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "sys_db_changelog_pkey"
  Detail: Key (script_name)=(70-myar/update/postgres/16/161209-0-dropCustomerAddress.sql) already exists
  1. If I remove the module myic (inventory control) form myacct then clean and assemble the project, I get the attached warning message and the details of the exception looks like below:

After I try to update get the attached database update scripts

REVISED feedback (that posted 1 hour ago) -didn’t have option to edit…

Hi Konstantin
Today I am getting almost similar exceptions and would like to share with you that might help your investigation:

I have several modules (as app components) and some of them are using more than one app components as described below:

  1. module: myap
  • app component used: myutil
  1. module: myic
  • app component used: mutil
  1. module: myar
  • app component used: mutil and myic
  1. module: myacct (accounts)
  • app component used: mutil, myic, myproc, myar

Note there that myar module is using myic (it’s not cross-referenced) but myic is used by this module as well as it is directly used by myacct. myutil is used by all modules though. All of the above modules work well except the last one i.e. myacct. Two different kind of behavior I see as follows:

  1. clean and Assemble works well but while running i am getting warning message regarding update scripts as attached.! When I run update i am getting the following error message:

[21:56:37.196] Updating database jdbc:postgresql://localhost/myems
:accounts-core:assembleDbScripts UP-TO-DATE
:accounts-core:updateDb
Script 70-myar/init/postgres/10.create-db.sql has not been applied, running init scripts
Executing SQL script: D:\Studio Projects\ems\myacct\modules\core\build\db\70-myar\init\postgres\10.create-db.sql
Failed to execute: -- begin MYAR_CREDIT_STANDARD
create table MYAR_CREDIT_STANDARD (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    --
    NAME varchar(255),
    CREDIT_PERIOD integer,
    INTEREST_BEARING boolean,
    --
    primary key (ID)
) because: ERROR: relation "myar_credit_standard" already exists
Failed to execute: insert into SYS_DB_CHANGELOG (SCRIPT_NAME, IS_INIT) values (?, ?) because: ERROR: duplicate key value violates unique constraint "sys_db_changelog_pkey"
  Detail: Key (script_name)=(70-myar/update/postgres/16/161209-0-dropCustomerAddress.sql) already exists.

:accounts-core:updateDb FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':accounts-core:updateDb'.
> org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "sys_db_changelog_pkey"
  Detail: Key (script_name)=(70-myar/update/postgres/16/161209-0-dropCustomerAddress.sql) already exists.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 4.612 secs
[21:56:46.818] Task 'updateDb' failed
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "sys_db_changelog_pkey"
  Detail: Key (script_name)=(70-myar/update/postgres/16/161209-0-dropCustomerAddress.sql) already exists.

It apparently appears that Entity names CREDIT_STANDARD and CustomerAddress are repeated in more than one app component but it is not the case. In order to avoid this, I recreated the entity as new CREDIT_STANDARD as I was getting similar error message for another Entity CREDIT_PROFILE

CustomerAddress is used twice as billToAddress and shipToAddress in Entity CustomerInvoice (billToAddress) and CustomerInvoiceGood (shipToAddress) of module myar where CustomerInvoice is parent Entity of CustomerInvoiceGood. I’m not sure if there is something wrong here!

I look forward for your update.

Hi Mortoza,

Thank you for the feedback, Rostislav will look into it.

Hi Mortoza,

Could you please check the contents of D:\Studio Projects\ems\myacct\modules\core\build\db</i>. Are there several XX-myar folders (f.e. “60-myar” and “70-myar”)?

In the platform version 6.3.5 we have fixed the issue which can cause the problem. Try to upgrade all your projects, rebuild and reinstall them to Maven.
After the component is successfully reinstalled, the ~\.m2\repository\com\company\project_name\prefix-core\0.1-SNAPSHOT\prefix-core-0.1-SNAPSHOT-db.zip artifact should contain only one folder with DB update scripts. So scripts doubling should not occur.

Hi Rostislav
Thanks for the new version. I have recompiled it (cleaned, assembled, recreate comp, install those modules and they are running but when i trying to run the myacct module that is using few other modules (app component) it is still through exception. When it thrown for another Entity under the same module and I deleted that now it is showing another entity as exception:


:accounts-core:assembleDbScripts UP-TO-DATE
:accounts-core:updateDb
Script 70-myar/init/postgres/10.create-db.sql has not been applied, running init scripts
Executing SQL script: D:\Studio Projects\ems\myacct\modules\core\build\db\70-myar\init\postgres\10.create-db.sql
Failed to execute: 
-- end MYAR_CREDIT_STANDARD
-- begin MYAR_DEBIT_NOTE
create table MYAR_DEBIT_NOTE (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    --
    DOC_NUMBER bigint,
    DOC_DATE date,
    CUSTOMER_ID uuid,
    SALES_INVOICE_ID uuid,
    DESCRIPTION varchar(255),
    CURRENCY_ID uuid,
    MEMO_STATUS integer,
    --
    primary key (ID)
) because: ERROR: relation "myar_debit_note" already exists
Failed to execute: insert into SYS_DB_CHANGELOG (SCRIPT_NAME, IS_INIT) values (?, ?) because: ERROR: duplicate key value violates unique constraint "sys_db_changelog_pkey"
  Detail: Key (script_name)=(70-myar/update/postgres/16/161209-0-dropCustomerAddress.sql) already exists.

:accounts-core:updateDb FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':accounts-core:updateDb'.
> org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "sys_db_changelog_pkey"
  Detail: Key (script_name)=(70-myar/update/postgres/16/161209-0-dropCustomerAddress.sql) already exists.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 45.682 secs
[00:45:17.725] Task 'updateDb' failed
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "sys_db_changelog_pkey"
  Detail: Key (script_name)=(70-myar/update/postgres/16/161209-0-dropCustomerAddress.sql) already exists.

directories in myacct looks like as below:

  • 10-cuba
  • 50-myutil
  • 60-myic
  • 60-myproc
  • 70-myar
  • 80-myacct

Hi Mortoza,

A first, I should say that it is very hard to guess the reason of the problem, as I could not reproduce it in my testing environment.

As I understood:

  1. Your “MyAr” project includes “MyIC” and “MyUtil” components and it works well.
  2. Your “MyAcc” project includes “MyAr” and “MyProc” components and it could not start due to the error.

Have you recreated the database or you run update scripts on the already existent one? May be, it has already the table with the specified name.

As I see the “MyProc” project has also one custom component as the name of the folder (“60-myproc”) starts with “60”. So could you say which component is attached to “MyProc”?

Could you also check the namespace of the “MyProc” project. Name of a database table is built based on the project namespace and the name of the entity. And if your “MyProc” has the namespace “myAr” and an entity with the name “DebitNote” - that is the reason.

Let me explain how the Db update works on the project with components:

  1. Scripts are sorted by their names (that is why the name is started with digits), the scripts are run one by one.
  2. In your “MyAr” project scripts are executed: 10-cuba -> 50-myutil -> 60-myic ->70-myar. And everything is OK.
  3. In your “MyAcc” project scripts are executed: 10-cuba -> 50-myutil -> 60-myic -> 60-myproc ->70-myar. And 70-myar fails.

The error says that the table from 70-myar already exists in the database. Maybe it is created by the 60-myproc scripts?

Please look through all the scripts(start from the “myproc” folder) to discover which of them create the “myar_debit_note” table.

Hi Rostislav
Please note that myic has both direct and indirect using in myacct as attached, is this the reason? Meanwhile, I’m going to check all of them as you mentioned in your feedback.

app components

Additional update:

while I tried to recreate the database from myIc module i am getting the following error.


Failed to execute: 
-- end MYIC_STOCK_TRANSFER_ORDER_LINE
-- begin MYIC_OPTION
alter table MYIC_OPTION add constraint FK_MYIC_OPTION_COMPANY foreign key (COMPANY_ID) references MYACCT_COMPANY(ID) because: ERROR: relation "myacct_company" does not exist
:inventorycontrol-core:createDb FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':inventorycontrol-core:createDb'.
> org.postgresql.util.PSQLException: ERROR: relation "myacct_company" does not exist

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Note that I had that company reference earlier and no more existing. I dropped the whole database, recreated and getting the same exception. Therefore, it seems that the change of Entity relation in Studio is not refreshing the scripts.

Reference your DB update steps; if that is so, what do you suggest CUBA will work when I have the usage/reference to different modules as per the diagram attached in my previous post?

Hi,

Let me ensure, I have correctly understood the structure of your system:

  1. MyIC project - is a component. In Studio you have generated App component descriptor and installed the project to Maven. Right?
  2. After that, MyIC component has been included to MyAcc*. You have opened the project properties of *MyAcc and added the Custom component choosing MyIC the from the dropdown. Right?
  3. The MyAcc project is on top. It uses all the components. Right?

Could you please describe how do you recreate the database?

If all above is right, please describe how the MYIC_OPTION entity can have a link to MYACCT_COMPANY?
The MyAcc entities are unreachable from MyIC*, as the *MyAcc component is not added to MyIC.

Yes I followed all of the above 1, 2, 3.
Before I realized the cross-reference is not possible in CUBA, I had an entity named Company in myAcc and used it as Foreign key from the module myIC. Later I removed the Entity Company from myAcc, created it in MyUtil and I also have removed the relationship with this Entity. But surprisingly, the studio didn’t remove the Foreign Key reference to the old Entity Company located in myAcc which is no longer existing. It should have been deleted when i deleted the entity from myAcc. Now it is reporting as follows. Seems like the script is now redundant, how can I clean/recreate the script?


* What went wrong:
Execution failed for task ':inventorycontrol-core:createDb'.
> org.postgresql.util.PSQLException: ERROR: relation "myacct_company" does not exist

Is there any bugs or I’m doing something incorrect!