Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Import.groovy
- includeTargets << grailsScript("Bootstrap")
- target(main: "Import some data...") {
- depends(bootstrap)
- def Channel = grailsApp.classLoader.loadClass("content.Channel")
- def c
- // works: saving a valid Channel succeeds
- c = Channel.newInstance(title:"A Channel", slug:"a-channel", position:0).validate()
- // doesn't work: saving an invalid Channel fails with exception
- c = Channel.newInstance().validate()
- // this line is never reached due to exception
- println(c.errors)
- }
- setDefaultTarget(main)
- // Import.groovy
- def Channel = grailsApp.classLoader.loadClass("content.Channel")
- def c
- c = Channel.newInstance(title:"A Channel", slug:"a-channel", position:0).validate()
- c = Channel.newInstance().validate()
- println(c.errors)
- // Import.groovy
- includeTargets << grailsScript("Bootstrap")
- target(main: "Import some data...") {
- depends(bootstrap)
- // added this ------------------------------------------------------
- def sessionFactory = appCtx.getBean("sessionFactory")
- def session = SessionFactoryUtils.getSession(sessionFactory, true)
- TransactionSynchronizationManager.bindResource(
- sessionFactory, new SessionHolder(session))
- // added this ------------------------------------------------------
- def Channel = grailsApp.classLoader.loadClass("content.Channel")
- def c
- // works: saving a valid Channel succeeds
- c = Channel.newInstance(title:"A Channel", slug:"a-channel", position:0).validate()
- // doesn't work: saving an invalid Channel fails with exception
- c = Channel.newInstance().validate()
- // this line is never reached due to exception
- println(c.errors)
- }
- setDefaultTarget(main)
Add Comment
Please, Sign In to add comment