Using Postgresql with Grails
Posted by Jim Morris on Wed Nov 11 13:59:07 -0800 2009
I started playing with Grails, and I am planning to rewrite the blog engine I use for this blog in Grails. As noted earlier I wrote it in Merb originally. Although Merb is nice and lite it seems to be having difficulty keeping up with the gems it is dependent on. A case in point is Cucumber which it says is its recommended way of doing integration tests. The current version of Cucumber is very difficult to get working with Merb. See the Git source to see how I finally did it.
While I was learning Grails, I hooked up Postgresql 8.2 to Grails
using the Datasource.groovy
file. I turned on SQL logging, and to my
horror saw how it was handling the id's. I have been using Postgresql
for quite a while now, and used to run into problems with the creation
and retrieval of the automatically generated IDs. It seems a lot of
people run into these hard to describe problems, as it appears to
happen rarely and is probably a race condition. With version >= 8.2
Postgresql introduced a way of inserting a new record and returning
the automatically generated id in one atomic statement. This solves
all the problems and is more efficient as it does not require two
queries for each insert.