tags:

views:

46

answers:

0

Hello, I was trying the grails sample programs from http://github.com/grails/grails-samples.git . It is also part of the Definitive Guide To Grails book. The steps (as per grails-samples/dgg/README.txt).

  1. Installed mySql --> created user (gtunes), db (gtunes_ch17) etc
  2. set GRAILS_HOME, PATH to grails 1.1 ver
  3. Grails upgrade
  4. grails app-run

    the application starts fine. Now I'm trying to load the sample data

grails import-library-from-xml ../gtunes-data.xml

This gives error. The import function is defined in ImportLibraryFromXml.groovy, which loads the data from gtunes-data.xml file.

Artist.withTransaction { status ->
        Artist.withSession { session ->
            for(a in xml.artist) {
                def artist = new Artist(name:[email protected]()).save()
                println "Importing artist $artist.name.."
                for(alb in a.album) {
                    def album = new Album(title:[email protected](),
                                                       genre:[email protected](),
                                                       year:[email protected](),
                                                       price:[email protected]()).save()
                    artist.addToAlbums(album)
                    alb.song.eachWithIndex { s, i ->

                        def song = new Song(title:[email protected](),
                                                         duration:[email protected](),
                                                         file:[email protected](),
                                                         trackNumber:i+1,
                                                         genre: album.genre,
                                                         year: album.year,
                                                         artist:artist).save()
                        album.addToSongs(song)
                    }
                }
               if(!artist.save(flush:true)) {
                   status.setRollbackOnly()
                   println "Import Failed: Validation error occured import artist ${artist.name}, data appears corrupt."
                   break
               }
               session.clear()
            }
        }

        if(!status.isRollbackOnly()) {
            println "Import Successful."
        }
    }

The function works if I comment out album and songs section. That is the Artist is get saved. I doubt it is something to do with transient state of the contained object, but couldn't see anything obvious. Any pointers would highly appreciated.

thanks..