29 May 2011

Definitive Guide to Grails Sample Code Issues

As I mentioned in a previous post, I've been reading the Definitive Guide to Grails by Graeme Rocher and Jeff Brown. In that post, I documented how to install the sample code used in the book.

The sample code was developed with Grails 1.1 and I ran into numerous issues trying to get the samples to work under Grails 1.3.7. Here are the list of issues I ran into and how I resolved them. Remember, to execute the grails upgrade command as described in the sample code README.TXT.

Create Sample Database & Update DataSource.groovy

Although not an issue with the sample code, you must create an empty msql database for the sample to work. I provided the mysql commands in an earlier post.

If you're using a different username or database, update the DataSource.Groovy parameters as appropriate.

dataSource {
   pooled = true
   url = "jdbc:mysql://localhost/gtunes_chxx"
   driverClassName = "com.mysql.jdbc.Driver"
   username = "gtunes"
   password = "password"
}

 

OSCacheProvider Issue

In the DataSource.Groovy file change the line:

cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'

To

cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'

No Hibernate Session bound to thread

I encountered this issue when trying to run the ImportItunesLibrary service that is briefly described in the README.TXT. Insert the following after the existing import statements in the ImportItunesLibrary.groovy file.

// Imports for configureHibernateSession()
import org.springframework.orm.hibernate3.SessionFactoryUtils
import org.springframework.orm.hibernate3.SessionHolder
import org.springframework.transaction.support.TransactionSynchronizationManager

def configureHibernateSession() {
  def sessionFactory = appCtx.getBean("sessionFactory")
  def session = SessionFactoryUtils.getSession(sessionFactory, true)
  TransactionSynchronizationManager.bindResource(sessionFactory,
      new SessionHolder(session))
}

 

Then insert the following line before the call to importItunesLibrary().

configureHibernateSession()

grails upgrade

As described in the readme file, execute the command to upgrade the the code:

$ grails upgrade

Import iTunes Library

While only briefly mentioned in the readme file, there is a script to import your iTunes library into the sample gTunes application. Copy your iTunes XML file to the grails directory (windows users will find this in C:UsersMusiciTunesitumes Music Library.xml). I called my gregLib.xml and execute the command:

$ grails importItunesLibrary ../gregLib.xml


Tags:
0 comments