[[db-schemas]]
= Database Schemas

:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


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 link:https://crate.io/docs/sql-99/en/latest/chapters/17.html#create-schema-statement[here]).

We recommend all the entities within a module use the same schema, and moreover that the xref:refguide:applib:index/annotation/DomainObject.adoc#logicalTypeName[object type] also follows the same pattern.

For example, xref:security:secman:about.adoc[SecMan]' JDO implementation resides in the `CausewayModuleExtSecmanPersistenceJpa` module.
Its `ApplicationUser` entity is defined as:

[source,java]
.ApplicationUser.java
----
import javax.jdo.annotations.PersistenceCapable;

@PersistenceCapable(
        schema = "causewayExtSecman",
        table = "ApplicationUser",
        ...
)
public class ApplicationUser ... { /* ... */ }
----

which results in a `CREATE TABLE` statement of:

[source,sql]
----
CREATE TABLE causewayExtSecman."ApplicationUser" (
    ...
)
----



[TIP]
====
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 `@PersistenceCapable` annotation by providing XML metadata (the `mappings.jdo` file).
See the section on xref:pjdo:ROOT:setup-and-configuration.adoc[configuring DataNucleus Overriding Annotations] for more details.
====


include::refguide:config:partial$configuring-schemas.adoc[leveloffset=+1]

