The following grails script:
// 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)
fails with the exception:
Error executing script Import: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
when validate() is called on an invalid domain object. I'd like to output the error messages when validation fails, however it seems I'll need to establish a hibernate session in order to do so. Anyone know a way to get past this?