GRAILS with PostgreSQL Gotcha

Everyone is talking about PostgreSQL these days. Especially folks that discover that they are running MySQL illligaly because it´s libs are under the GPL ;-) ).

In case you want to check out GRAILS in conjunction with PostgreSQL (gosh – what a name) save yourself some time and don´t call your user domain model ‘user’ because it will fail on database deployment.

column notation .id applied to type “name”, which is not a composite type

That is because User is a reserved table name for PostgreSQL. So call it Person or what not and it will work just fine.

Here is the complete DataSource file to get you up and running quickly:

dataSource {
pooled = false
url = "jdbc:postgresql://localhost:5432/dbDev"
driverClassName = "org.postgresql.Driver"
dialect = org.hibernate.dialect.PostgreSQLDialect
username = "user"
password = "passwordd"
}
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
url = "jdbc:postgresql://localhost:5432/dbDev"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:postgresql://localhost:5432/dbTest"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:postgresql://localhost:5432/dbProd"
}
}
}

2 comments so far

  1. John M on

    I ran across this today will reading “Beginning Groovy and Grails From Novice to Professional” from Apress. The examples use domain User and when you try to use a Postgresql data source you see the error. Here are my logs:

    2009-06-14 07:50:56 EDT STATEMENT: create table user (id int8 not null, version int8 not null, first_name varchar(255) not null, last_name varchar(255) not null, user_name varchar(255) not null unique, primary key (id))
    2009-06-14 07:50:56 EDT ERROR: syntax error at or near “user” at character 88

    You would think the creation statement would use double quotes around the domain “user” because Postgres will then allow the table to be created.

  2. Chris on

    Good article. Thanks!


Leave a reply