Entity schema reference
The file consumed by spring-cli schema apply is a JSON object with a required entities object. Each property name is an entity key used to derive the Java class name and to identify relation targets.
{
"entities": {
"product": {
"tableName": "products",
"id": {
"name": "id",
"type": "long",
"strategy": "identity"
},
"attributes": {
"name": {
"databaseColumn": "name",
"type": "string",
"required": true
}
},
"relations": {
"category": {
"kind": "ManyToOne",
"target": "category",
"joinColumn": "category_id",
"required": true
}
}
},
"category": {
"tableName": "categories",
"id": {
"name": "id",
"type": "long",
"strategy": "identity"
}
}
}
}Entity fields
| Property | Required | Description |
|---|---|---|
tableName | Yes | Value used in @Table(name = "..."). |
id | Yes | ID field definition. |
attributes | No | Object of ordinary persisted fields, keyed by logical attribute name. |
relations | No | Object of JPA relationships, keyed by logical relation name. |
Each id object requires a non-empty name and a supported type. Its strategy is optional and defaults to none when generating the class.
Each attribute requires databaseColumn and type. required: true generates a non-null column mapping. If omitted or false, no non-null constraint is added.
Supported Java types
| Schema type | Java type |
|---|---|
string | String |
text | String |
int | Integer |
long | Long |
boolean | Boolean |
double | Double |
bigdecimal | BigDecimal |
localdate | LocalDate |
localdatetime | LocalDateTime |
instant | Instant |
uuid | UUID |
ID strategies
| Strategy | Generated mapping |
|---|---|
identity | @GeneratedValue(strategy = GenerationType.IDENTITY) |
uuid | @GeneratedValue(strategy = GenerationType.UUID) |
none | No generated-value annotation |
If strategy is omitted, the generated class uses none.
Relations
Each relation requires kind and target. target must match another key in the entities object.
| Kind | Optional properties used during generation |
|---|---|
ManyToOne | joinColumn, required |
OneToOne | joinColumn, mappedBy, required |
OneToMany | mappedBy |
ManyToMany | joinTable, mappedBy |
required: true marks supported to-one relationships as non-optional. For OneToOne, set mappedBy on the inverse side; otherwise, joinColumn can name the owning-side column. For ManyToMany, use joinTable on the owning side or mappedBy on the inverse side.
schema apply generates JPA mappings and JavaBean accessors; it does not create or migrate a database schema. Review the generated entity relationships for your persistence design.