Search code examples
apache-cayenne

How can I define multi-column unique constraints with Apache Cayenne?


As is often the case in normalized database model design I want to define a multi-column unique constraint in addition to the auto-generated primary key constraint for a table that Apache Cayenne allows me to define via the modeling UI. Is it possible to tell Cayenne that a particular column or group of columns must be unique for a given table?

EG- An app_user table defined as (postgresql syntax):

pid bigint not null primary key,
id varchar(100) not null,
full_name varchar(100)

where the id column must be unique.

The only way I can think of is to create post-processing scripts that must be executed after the database has been created to define the additional constraints, but I am hoping there is a better way via Cayenne. Am I missing something?

This is the only relevant discussion I was able to find on the subject: http://markmail.org/message/euetcwcn73tfd45o


Solution

  • I can quote the reply that I made in the mentioned discussion thread: "DB concepts not directly related to ORM are generally ignored". So yes, unfortunately Cayenne does not have facilities to model unique constraints.