One of Cayenne core features is automatic generation of the database primary keys for the new objects. This requires a set of special database objects to be present in the database. Those are adapter-specific and can be special lookup tables, stored procedures, sequences, etc. If the database schema was generated by CayenneModeler as described in previous chapters, chances are that all needed database objects were already created. Otherwise, if there was an existing schema, these objects must be created in the database. The easiest way to do that is to use CayenneModeler "Tools > Generate Database Schema" menu item, setting special generation options.
Create Primary Key Support. Select a DataMap and choose "Tools -> Generate Database Schema" from the menu, "Connect to Database" dialog appears.
Configure Database Connection. "Connect to Database" dialog allows to specify alternative connection parameters. If a DataMap has a DataNode, then this DataNode connection information is shown by default. You can use suggested default connection, select one of the stored local DataSources from "Saved DataSources" dropdown (those can be edited on the spot by clicking "..." button), or type your own info. When desired connection is selected, click "Continue". Cayenne will attempt to connect to the database and if connection is successful, "Options" dialog is presented.
You must uncheck all options except for "Create Primary key Support", and then click "Generate". If there were any database specific errors during generation they will be listed in a status window. Sometimes such errors can be simply ignored (e.g. when a there was an existing primary key support already configured in the DB).