> 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/getting-started/configuration/custom-hibernate-config.md).

# Custom Hibernate Config

Sometimes bx-orm doesn't have a dedicated setting for a Hibernate property you need. There are two ways to set arbitrary Hibernate properties directly: a `hibernate.properties` file via `ormconfig`, or an inline struct via `hibernateProperties`.

### ormConfig: A Properties File

Point `ormconfig` at a flat, standard Java `hibernate.properties`-formatted file:

```js
this.ormSettings = {
    // ...
    ormconfig : "./config/hibernate.properties"
};
```

The file is a simple list of `key=value` pairs, one Hibernate property per line:

```properties
# hibernate.properties
hibernate.connection.release_mode=on_close
hibernate.use_sql_comments=true
```

{% hint style="warning" %}
Only the flat `key=value` properties file format is supported. The XML `hibernate.cfg.xml` format is not yet implemented.
{% endhint %}

### hibernateProperties: An Inline Struct

For settings you'd rather keep alongside the rest of your ORM config instead of in a separate file, use the `hibernateProperties` struct:

```js
this.ormSettings = {
    // ...
    hibernateProperties = {
        "hibernate.connection.release_mode" = "on_close",
        "hibernate.use_sql_comments" = "true"
    }
};
```

Every entry is applied directly to the Hibernate configuration, giving you an escape hatch for tuning any Hibernate setting bx-orm doesn't expose a dedicated setting for.

### Precedence

Both settings are applied **after** bx-orm's own internal defaults, so either can override bx-orm's hardcoded Hibernate settings (e.g. flush and auto-close behavior). When using both together:

1. `ormconfig` (the file) is applied first.
2. `hibernateProperties` (the inline struct) is applied second, so it wins on a conflicting key.

{% hint style="info" %}
A handful of settings that are load-bearing for bx-orm's own correctness (JDBC connection provider wiring, classloaders, session context class, identifier quoting, and entity mode) are re-applied internally *after* `ormconfig` and `hibernateProperties` are processed, so neither can break those specific things no matter what you set.
{% endhint %}

### Example: Fixing Cross-Database "Statement Is Closed" Errors

If your app runs against multiple database engines (e.g. MySQL, MSSQL, PostgreSQL) you may see Hibernate `"statement is closed"` errors on MSSQL or Postgres, caused by stale JDBC statements after per-save transaction commits. Setting `hibernate.connection.release_mode` per-app resolves this:

```js
this.ormSettings = {
    // ...
    hibernateProperties = {
        "hibernate.connection.release_mode" = "on_close"
    }
};
```


---

# 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/getting-started/configuration/custom-hibernate-config.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.
