> For the complete documentation index, see [llms.txt](https://bxorm.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bxorm.ortusbooks.com/modeling/entities.md).

# Entities

Learn the basics of modeling ORM entities

A persistent entity is a boxlang class that is marked as a database entity via the `persistent` annotation upon the class definition:

```js
class persistent="true"{

}
```

By default, the entity name will be the boxlang class file name - minus the file extension, of course. We can modify the entity name via the `entityname` annotation:

```js
class persistent="true" entityname="Author" {

}
```

And the table name via the `table` annotation:

```js
class persistent="true" entityname="Author" table="authors" {

}
```

Here's the full list of available annotations for a persistent class:

| Attribute             | Type      | Default | Description                                                                                                                 |
| --------------------- | --------- | ------- | --------------------------------------------------------------------------------------------------------------------------- |
| `persistent`          | `boolean` | `false` | Mark this class as an ORM entity                                                                                            |
| `entityname`          | `string`  |         | Set a custom entity name which is different than the boxlang class name                                                     |
| `table`               | `string`  |         | Specify the database table name                                                                                             |
| `schema`              | `string`  |         | Specify the database schema name.                                                                                           |
| `catalog`             | `string`  |         | Specify the database catalog name.                                                                                          |
| `dynamicinsert`       |           |         | Specifies whether INSERT SQL is generated at runtime. Only columns whose values are not null are included in the SQL.       |
| `dynamicinsert`       | `boolean` | `false` | Specifies whether INSERT SQL is generated at runtime. Only columns whose values are not null are included in the SQL.       |
| `dynamicupdate`       | `boolean` | `false` | Specifies whether UPDATE SQL is generated at runtime. Only columns whose values are not null are included in the SQL.       |
| `readonly`            | `boolean` | `false` | Specify whether the table is read-only.                                                                                     |
| `selectbeforeupdate`  | `boolean` |         | Specify whether Hibernate should perform an SQL `UPDATE` only when an object is actually modified.                          |
| `optimisticlock`      | `string`  |         | Determines the locking strategy: `all`, `dirty`, `version`, or `none`.                                                      |
| `batchsize`           | `integer` |         | Number of records to retrieve at a single instance.                                                                         |
| `lazy`                | `boolean` | `true`  | Whether loading is done lazily.                                                                                             |
| `rowid`               | `string`  |         | Specify the row ID.                                                                                                         |
| `discriminatorColumn` | `string`  |         | Define the discriminator column used in inheritance mapping.                                                                |
| `discriminatorValue`  | `string`  |         | Define the discriminator value used in inheritance mapping.                                                                 |
| `joinColumn`          | `string`  |         | Define a join column for inheritance mapping.                                                                               |
| `mappedSuperClass`    | `boolean` | `false` | Mark a non-persistent parent class as a mapped superclass. Its properties are folded into each persistent subclass's table. |
| `embedded`            | `boolean` |         | Mark the class as embedded so its properties are persisted with the parent's data.                                          |
| `cacheUse`            | `string`  |         | Caching strategy: `read-only`, `nonstrict-read-write`, `read-write`, or `transactional`.                                    |
| `cacheName`           | `string`  |         | Specify the name of the secondary cache.                                                                                    |
| `cacheInclude`        | `string`  | `all`   | Set to `non-lazy` to exclude lazy-loaded properties from the secondary cache entry.                                         |
| `saveMapping`         | `boolean` | `false` | Save the generated Hibernate mapping file as `{class name}.hbm.xml` beside the BoxLang class.                               |
| `datasource`          | `string`  |         | Name a specific datasource to persist this entity to.                                                                       |

### Sharing Properties with `mappedSuperClass`

Use `mappedSuperClass` when you want several entities to share a set of properties (like audit columns) without those properties living in their own database table:

```js
// BaseEntity.bx - not persistent itself
class mappedSuperClass="true" {
    property name="createdDate" ormType="timestamp";
    property name="modifiedDate" ormType="timestamp";
}

// Author.bx
class persistent="true" extends="BaseEntity" {
    property name="authorID" fieldtype="id";
    property name="name" ormType="string";
    // createdDate and modifiedDate columns are added to the "Author" table
}
```

This differs from `joinColumn`/`discriminatorValue` inheritance, where subclasses share rows through a join or a discriminator column in a single parent table. With `mappedSuperClass`, there is no parent table at all: every property is copied into each subclass's own table.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://bxorm.ortusbooks.com/modeling/entities.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
