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 object type also follows the same pattern.
For example, SecMan' JDO implementation resides in the CausewayModuleExtSecmanPersistenceJpa
module.
Its ApplicationUser
entity is defined as:
import javax.jdo.annotations.PersistenceCapable;
@PersistenceCapable(
schema = "causewayExtSecman",
table = "ApplicationUser",
...
)
public class ApplicationUser ... { /* ... */ }
which results in a CREATE TABLE
statement of:
CREATE TABLE causewayExtSecman."ApplicationUser" (
...
)
If for some reason you don’t want to use schemas (though we strongly recommend that you do), then note that you can override the |
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).