////
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

https://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.
////

You can refer to the link:../api/org/grails/orm/hibernate/connections/HibernateConnectionSourceSettings.html[HibernateConnectionSourceSettings] class for all available configuration options, but below is a table of the common ones:

[format="csv", options="header"]
|===
name,description,default value
`grails.gorm.flushMode`, The flush mode to use, `COMMIT`
`grails.gorm.failOnError`, Whether to throw an exception on validation error, `false`
`grails.gorm.default.mapping`,The default mapping to apply to all classes, `null`
`grails.gorm.default.constraints`,The default constraints to apply to all classes, `null`
`grails.gorm.multiTenancy.mode`,The multi tenancy mode, `NONE`
|===

The following are common configuration options for the SQL connection:

[format="csv", options="header"]
|===
name,description,default value
`dataSource.url`, The JDBC url, `jdbc:h2:mem:grailsDB`
`dataSource.driverClassName`, The class of the JDBC driver, detected from URL
`dataSource.username`, The JDBC username, `null`
`dataSource.password`, The JDBC password, `null`
`dataSource.jndiName`, The name of the JNDI resource for the `DataSource`, `null`
`dataSource.pooled`, Whether the connection is pooled, `true`
`dataSource.lazy`, Whether a `LazyConnectionDataSourceProxy` should be used, `true`
`dataSource.transactionAware`, Whether a `TransactionAwareDataSourceProxy` should be used, `true`
`dataSource.readOnly`, Whether the DataSource is read-only, `false`
`dataSource.options`, A map of options to pass to the underlying JDBC driver, `null`
|===

And the following are common configuration options for Hibernate:

[format="csv", options="header"]
|===
name,description,default value
`hibernate.dialect`, The hibernate dialect to use, detected automatically from DataSource
`hibernate.readOnly`, Whether Hibernate should be read-only, `false`
`hibernate.configClass`, The configuration class to use, `HibernateMappingContextConfiguration`
`hibernate.hbm2ddl.auto`, Whether to create the tables on startup, `none`
`hibernate.use_second_level_cache`, Whether to use the second level cache, `true`
`hibernate.cache.queries`, Whether to cache queries (see Caching Queries), `false`
`hibernate.cache.use_query_cache`, Enables the query cache, `false`
`hibernate.configLocations`, Location of additional Hibernate XML configuration files
`hibernate.packagesToScan`, Specify packages to search for autodetection of your entity classes in the classpath
`hibernate.grails.proxy.lazy_to_string`, Whether `toString()` on an uninitialized proxy avoids initializing it (see Proxies and toString()), `false`
|===

In addition, any additional settings that start with `hibernate.` are passed through to Hibernate, so if there is any specific feature of Hibernate you wish to configure that is possible.


==== Proxies and toString()


Grails proxies answer identifier access (`id`, `getId()`, `ident()`) and `metaClass` access without initializing the proxy. By default, calling `toString()` on an uninitialized proxy initializes it and delegates to the domain class's own `toString()` implementation.

If you prefer `toString()` to also avoid initialization — for example to keep log statements from triggering database access — enable lazy `toString()` in `application.yml`:

[source,yaml]
----
hibernate:
    grails:
        proxy:
            lazy_to_string: true
----

With this setting enabled, `toString()` on an uninitialized proxy returns `entityName:id` (for example `com.example.Author:1`) without initializing it. Once the proxy has been initialized, `toString()` always delegates to the domain class's implementation.

TIP: The above table covers the common configuration options. For all configuration refer to properties of the link:../api/org/grails/orm/hibernate/connections/HibernateConnectionSourceSettings.html[HibernateConnectionSourceSettings] class.
