Primary keys

A primary key is a unique key that is part of the definition of a table. It can be used to distinguish one record from others. All records must have a primary key. When you create a new record in a table, you may need to generate a unique primary key for the record.

In the HCL Commerce programming model, the persistence layer includes JPA entities that interact with the database. As such, database records may be created when an JPA entity is instantiated. Therefore, before a new JPA entity becomes persistent, it may need to include logic to generate a primary key for new records.

When an application requires information from the database, it indirectly uses the JPA entities by instantiating the entity and then getting or setting various fields. A JPA entity is instantiated for a particular record in a database (for example, for a particular user profile) and it uses the primary key to select the correct information from the database.