Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Problem Statement

During development, we may be creating and removing fields from our form design. This would eventually lead to having unused columns in the database table. In this exercise, we will discuss how to organize a table structure and eventually remove the unused columns.

...

As we can see from the result, there are 10 forms pointing to the table now.

Cleaning Up the Table through the Forms

With this information on hand, we can now manually go to each of the 10 forms and identify which column/field that is still needed and delete the unused field in the form itself.

We can swiftly open up the form in the form builder by putting replacing the parameters as shown in the screenshot below.

...

If you do not have access to the database to execute the SQLs in this article, Joget has a built-in feature to find out the usages of the table too. You may click on "Advanced Tools" > "Table" to find out the usages of the same table name too.

We can only click on "Show Table Usage In Other Apps" too to find out the table's usages of the table in other apps.

Cleaning Up the Database Table

After we have gone through all the forms in the previous step, we can now move on to the database itself to remove the unused columns. This step must be done manually outside of Joget.

For example, we have determined that we would be removing the 3 fields discussed earlier. We can issue the following SQLs.

Code Block
languagesql
titleRemoving columns from the database
linenumberstrue
ALTER TABLE `jwdb`.`app_fd_sample` DROP COLUMN `c_field1`;
ALTER TABLE `jwdb`.`app_fd_sample` DROP COLUMN `c_field2`;
ALTER TABLE `jwdb`.`app_fd_sample` DROP COLUMN `c_field3`;

Generating Hibernate Mapping File

We will need to delete the hibernate mapping file created by Joget in the "wflow/app_forms" folder.

Look for the file with the exact same table name. In our case, we are looking for "app_fd_sample.hbm.xml"

Image Added

This step is critical so that Joget would transverse through all the forms that point to the table name to generate a new mapping file, which in turn, generates any missing columns back in the database table. By not deleting this file and force a refresh, Joget would continue to assume that the table structure is still the same as always.

There is no need to restart the Joget server for this. However, we would still recommend you to restart the server as the hibernate mapping files are cached for performance reasons. If you have dropped columns that are still being referenced to in any of the forms, Joget would fail to fetch the already deleted column and this would result in an error such as the following.

Code Block
titleError
ERROR 06 May 2020 17:34:38 org.hibernate.engine.jdbc.spi.SqlExceptionHelper  - (conn=20963) Unknown column 'app_fd_sam0_.c_name' in 'field list'
ERROR 06 May 2020 17:34:38 org.joget.apps.datalist.model.DataList  - Error retrieving binder rows
org.hibernate.exception.SQLGrammarException: could not extract ResultSet