Grails: How to use postgreSQL with Grails

1. open BuildConfig.groovy and comment out mavenRepo “http://download.java.net/maven/2/ under the repositories section and add this line under  dependencies section

    

repositories {
        // uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
        mavenRepo "http://download.java.net/maven/2/"

        //repo for spring-security
        mavenRepo "http://repo.spring.io/milestone/"
    }

dependencies {
        runtime "postgresql:postgresql:9.1-901.jdbc4"
    }


2. open DataSource.groovy file and edit the following :

dataSource {
    pooled = true
    driverClassName = "org.postgresql.Driver"
    dialect = "org.hibernate.dialect.PostgreSQLDialect"
    username = "iqbal"
    password = ""
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
//    cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
}

// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:postgresql://localhost:5432/seram"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:postgresql://localhost:5432/seram"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
            properties {
                maxActive = -1
                minEvictableIdleTimeMillis=1800000
                timeBetweenEvictionRunsMillis=1800000
                numTestsPerEvictionRun=3
                testOnBorrow=true
                testWhileIdle=true
                testOnReturn=false
                validationQuery="SELECT 1"
                jdbcInterceptors="ConnectionState"
            }
        }
    }
}

4 thoughts on “Grails: How to use postgreSQL with Grails

  1. Invaluable piece . I was fascinated by the information . Does someone know where I could acquire a sample 2006 OR 735-501 version to edit ?

Leave a Reply

Your email address will not be published. Required fields are marked *