Introduction

This page is designed to include some tips related to rebuilding the system when installing or upgrading modules, or upgrading Openbravo Core.

Before rebuilding

Before rebuilding the system, it's very important to make sure you've exported all the modules you had in development in the system. To be sure of this, mark all your developed modules as "In development", and then do:

ant export.database

This should export all the modules to xml files.

If you don't do this, the rebuild task could revert some non-exported developments.

While rebuilding

While rebuilding the system, it's very important that you do not close the Rebuild Window, or stop Tomcat or the database service.

Be patient, some rebuild tasks can take a while (specially if you are upgrading Openbravo Core).

After having rebuilt the system

In case the build was successful

If the rebuild was completely successful, you will get a green "Build succesful" message. You then need to restart Tomcat to be able to use the new installed modules, or the new version of Core. You can do this through the Rebuild Window by choosing the "Restart application container" option, and clicking on "Continue". Wait until you see the the login window again, and you are good to go!

In case the build had warnings

If the build had warnings, this means two things:

  • First, the application is stable, and you should be able to restart Tomcat and login into Openbravo.
  • However, some problems happened, and you should check them. You should see some hints in the Rebuild Window itself (in the section Warnings and Errors). However, you can search for the full log message by clicking on the "Show log" button. If you already closed the Rebuild Window, you can see the log files inside your Openbravo sources folder, in the "log" folder.

Here are some tips of what you could do in case there were warnings:

  • If the warnings were in the "Database update" section of the rebuild, you should search for error messages in the "update.database" task execution in the log. It's most likely a problem related to Foreign Key constraints which were not activated for some reason, or other database objects not having been created. You should manually fix this problem by connecting to your database, and verifying why the foreign keys (or other database objects) couldn't be created. After you fix the problem, you should export your modules so that another rebuild doesn't cause the same problem.
  • If the warnings happened in the "generating entities" step of the rebuild, you should manually call ant generate.entities and see what log do you get. This should give some tips on how to solve the problem.
  • If the warnings happened in the "Source compilation" step, it's most likely a problem related to some java or xsql file. Check the log file to find out in which file the problem happened, and fix it. After you've fixed the problems, run ant smartbuild from the command line, and you should not see any more errors.

In case the build had critical errors

This is a very special case that has to be handled with extreme care. If there was a critical error in the build, this means that it is very possible that the data inside Openbravo is at risk.

The best course of action when a critical error happens is to restore a backup of your database. If this is not possible, then you need to find out the cause of the error, and take the necessary steps to ensure that your data is safe. These steps are very tricky, and require significant knowledge on how the Openbravo database works, so it is a good idea to contact with an expert before attempting to recover the data yourself, if you are not really sure of what you are doing.

The main cause of this error is that the rebuild failed while trying to recreate a database table. You will be able to find out which table was affected by looking at the error.

Let's assume that the C_Invoice table was affected. This means that the C_Invoice table either has been deleted and not created successfully, or created but with a problem which prevents your data from being inserted back into it.

In both cases, you need to make sure that the table exists and its design is correct and compatible with your data.

Once you have verified that the table exists, you need to copy your data back from the auxiliary table that the process has automatically created. In our example, you can do it by executing the following SQL command in the database:

INSERT INTO C_Invoice SELECT * FROM C_Invoice_

If this command succeeds, then your data is now safe. However, you still need to find out why the problem happened. The main cause of this problem is likely to be a module or industry template you just installed. If that is the case, then you can uninstall it, and rebuild the system:

ant smartbuild -Dlocal=no -Dforce=true

Important: Do not execute this command before making sure that your data has been moved correctly to the main table (in this example, C_Invoice). If the data is not moved before executing this command, it will be lost forever.

In case the build had other errors

If the build has errors, the build process is interrupted. As the build process is stopped, the application can be in a potentially unstable state. You will only be able to login using a user which has System Administrator role permission. Your objective in this case should be to fix the errors that caused the problems, and do a new rebuild which is succesful. Here are some tips on what you could try:

  • If the build stopped in the "Database update" step, most likely the database wasn't fully updated, and you will probably have problems logging into the application. You should look into the log to try to find which is the problem, fix it, and then do update.database so that the database is fully updated. Once this has been done, you can start a new build which should finish succesfully.
  • If the build stopped in the "generating entities" step, you should do ant generate.entities. This could work, or if it doesn't, it should provide tips on what you should fix.
  • If the build stopped in the "Source compilation" step, this is most likely related to some java or xsql file which contains errors. Try to find which file has problems by looking at the log messages, fix it, and then restart a build. If for some reason you cannot restart a build through the application, you can do a build by doing ant smartbuild in the command line.

In case module download hangs up

If the modules are being installed/updated online, it is possible the download process hangs up in case the Internet connection does not work properly or in case of problems in the remote server.

This can be noticed if after accepting the module(s) license the following window does not appear in a long time. Note that the download process can take several minutes to be completed depending on the number of modules downloaded and on the size of them. If you look in your log file you will see a line like INFO org.openbravo.erpCommon.modules.ImportModule - Installing /ws/pi-2/openbravo/modules/org.openbravo.examples.search.bankAccount/src-db/database/sourcedata/AD_REFERENCE.xml for each downloaded file and finishes with INFO org.openbravo.erpCommon.modules.ImportModule - Inserting in DB info for module: Bank Account Search, if this line does not appear is because the download did not finish.

The solution for this issue depends on whether the download was for an update or for a new module installation.

Update

In this case you will find in the backup_install directory a zip with the sources for the module (or core) as it was before the process. You will have to unzip it in the modules directory if it is a module or in the root openbravo directory for core.

After this you will be able to try to update the module again in the same way or download the obx file and update it locally from file system.

Installation

Go to modules directory and delete the folder for the module you were trying to update which is not complete.

After this you will be able to try to install the module again in the same way or download the obx file and install it locally from file system.

In case the build hangs up

Blocked database objects

If the process hangs up in the database update step, it is possible there was a blocked table that is causing a deadlock. These blocks can be produced by other processes/users accessing to database.

To solve this issue, you can follow these steps which are explained more in detail below:

  • Check if there're blocked objects
  • Unlock them
  • Re-run database update process and rebuild
Check for blocked objects

This check consists in executing a query in database. To do it you will have to connect to your openbravo database using a database client (for example psql for PostgreSQL or sqlplus for Oracle) with a user with dbadmin privileges.

  • PostgreSQL:
  SELECT c.relname, a.current_query   FROM pg_locks l, pg_class c, pg_stat_activity a  WHERE l.relation = c.oid    AND c.relname NOT LIKE 'pg%'    AND a.procpid = l.pid;
  • Oracle:
 
SELECT S.PROCESS, S.USERNAME, O.OBJECT_NAME, O.OBJECT_TYPE, s.PROGRAM, O.OWNER OWNER
FROM v$lock l,dba_objects o,v$session s
WHERE l.ID1 = o.OBJECT_ID
AND s.SID =l.SID
AND l.TYPE IN ('TM','TX');

These queries will return a list of the blocked tables and the process that caused the block.

Unlock blocked objects

If the previous step is positive (there are blocked objects), it will be necessary to unlock them before continuing.

The steps to perform are:

  • Stop tomcat, this will stop the database update process.
  • Try to kill the processes that are causing the block or restart the database service (PostgreSQL or Oracle).
Rerun the build

Once there are no blocked objects you will be able to run the build process again by executing in command line:

ant update.database compile.complete.deploy -Dforce=yes