This page last changed on Mar 27, 2006 by [email protected].


Configuring Start-up

Programmatic start-up configuration can be added a Grails application by creating one or many "BootStrap" classes in the "%PROJECT_HOME%\grails-app\conf" directory:

class ExampleBootStrap {

     @Property init = { servletContext ->
         // init app
     @Property destroy = {
         // destroy app

The "init" closure (if it exists) is called on application load and the "destroy" closure (again if it exists) on application exit


It is not guaranteed that destroy will be called unless the application exits gracefully (for example by using the application server's shutdown command) so don't rely on it too much

Configuring Data Sources

Data source names should end with "DataSource". There are four required String properties:

  • url - the JDBC url to the database
  • driverClassName - the JDBC driver class name
  • username - the username
  • password - the password
class HsqlDataSource {
   @Property String dbCreate = "update"
   @Property String url = "jdbc:hsqldb:hsql://localhost"
   @Property String driverClassName = "org.hsqldb.jdbcDriver"
   @Property String username = "sa"
   @Property String password = ""

By default org.apache.commons.dbcp.BasicDataSource is used, all of its properties can be added to data source classes. If you want to disable connection pooling create a "pooling" property and set it to false. This will use org.springframework.jdbc.datasource.DriverManagerDataSource instead. Properties configured on Grails data sources that are not supported by DriverManagerDataSource will silently be ignored.

@Property boolean pooling = false

If no (available) data sources are found Grails will start with an in-memory HSQLDB database with the database schema created at run-time.

By default Grails is configured to attempt to update or create the database on application load this is configured with the "dbCreate" property:

@Property String dbCreate= "update"

If this property is removed the database will have to be created manually or by a separate process. Other possible values for this property are "create" and "create-drop".

Grails supports the scenario where multiple data sources are configured and data is modified through only one data source. This scenario does not require global transactions. To support this your must configure your DAO's to have dependencies injected by name instead of by type.

Hibernate Configuration

When Hibernate 3 is set as the persistence strategy all persistent domain classes are mapped in a Hibernate configuration file.

Using other databases

Grails GORM is based on the Hibernate object/relational mapping framework. Therefore
Grails supports all Hibernate databases.

Hibernate is regularly tested with the following SQL databases:

  • DB2 7.1, 7.2, 8.1
  • HypersonicSQL 1.61, 1.7.0, 1.7.2, 1.8
  • Microsoft SQL Server 2000
  • MySQL 3.23, 4.0, 4.1, 5.0
  • Oracle 8i, 9i, 10g
  • PostgreSQL 7.1.2, 7.2, 7.3, 7.4, 8.0, 8.1
  • SAP DB 7.3
  • Sybase 12.5 (JConnect 5.5)
  • Timesten 5.1

Hibernate has also been tested with and is believed to be compatible with current versions of:

  • Apache Derby
  • HP NonStop SQL/MX 2.0 (requires Dialect from HP)
  • Firebird (1.5 with JayBird 1.01 tested)
  • FrontBase
  • Informix
  • Ingres
  • Interbase (6.0.1 tested)
  • Mckoi SQL
  • Pointbase Embedded (4.3 tested)
  • Progress 9

Using MySQL

Download the Java MySQL driver from:

Unpack the archive and copy the mysql*.jar (not the debug jar) to lib
in your grails application directory.

Change the ApplicationDataSource to using your own values:

class ApplicationDataSource {
    @Property boolean pooled = true
    @Property String dbCreate = "create-drop"
    @Property String url = "jdbc:mysql://localhost/yourDB"
    @Property String driverClassName = "com.mysql.jdbc.Driver"
    @Property String username = "yourUser"
    @Property String password = "yourPassword"


Debugging Hibernate

To log all SQL queries and all the stuff hibernate does, add the line, stdout

To the file in:

Document generated by Confluence on Mar 29, 2006 08:46