Database Schemas
In the same way that Java packages act as a namespace for domain objects, it’s good practice to map domain entities to their own (database) schemas. (For more on database schemas, see for example here).
We recommend all the entities within a module use the same schema, and moreover that the logical type name also follows the same pattern.
For example, SecMan' JPA implementation resides in the CausewayModuleExtSecmanPersistenceJpa
module.
Its ApplicationUser
entity is defined as:
@Entity
@Table(
schema = "causewayExtSecman",
name = "ApplicationUser",
...
)
public class ApplicationUser ... { /* ... */ }
which results in a CREATE TABLE
statement of:
CREATE TABLE causewayExtSecman."ApplicationUser" (
...
)
Configuring Schemas
While it is good practice to place tables in schemas, the ORMs do not by default actually create those schema (as per CREATE SCHEMA statement).
The framework therefore allows this to be configured:
-
causeway.persistence.schema.auto-create-schemas
whether to automatically create the schemas
-
causeway.persistence.schema.create-schema-sql-template
the SQL text used to create the schema. This should be an idempotent command, with the default being SQL-99 compliant:
CREATE SCHEMA IF NOT EXISTS %S
The string is interpolated using
String.format()
, passing in the schema name (for all discovered schema names).