views:

90

answers:

1
altEmailAddress(blank: true, nullable: true, validator: {
    if (it == null || it == '') {
        return true
    } else {
        return (User.countByEmailAddress(it) > 0 && User.countByAltEmailAddress(it) > 0)
    }
}

Stack trace:

Testcase: testFindValidEmailAddress took 0.429 sec
    Caused an ERROR
null
java.lang.StackOverflowError
    at com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    at com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    at com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    at com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    at com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    at com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    at com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    at com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    at com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    at com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    at com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    at com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    at com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
+4  A: 

You should use withNewSession - see http://adhockery.blogspot.com/2010/01/upgrading-grails-11-12.html

Edit: added for 1.1.x:

If you're not using 1.2 yet and withNewSession() isn't available, you can wire it up yourself in BootStrap:

import org.hibernate.Session
import org.springframework.orm.hibernate3.HibernateCallback
import org.springframework.transaction.support.TransactionSynchronizationManager
import org.springframework.orm.hibernate3.SessionHolder
import org.springframework.orm.hibernate3.HibernateTemplate

class BootStrap {

   def grailsApplication
   def sessionFactory

   def init = { servletContext ->
      for (domainClass in grailsApplication.domainClasses) {
         domainClass.metaClass.static.withNewSession = { Closure callable ->
            HibernateTemplate template = new HibernateTemplate(sessionFactory)
            SessionHolder sessionHolder = TransactionSynchronizationManager.getResource(sessionFactory)
            Session previousSession = sessionHolder?.session
            try {
               template.alwaysUseNewSession = true
               template.execute({ Session session ->
                  sessionHolder.addSession(session)
                  callable(session)
               } as HibernateCallback)
            }
            finally {
               if (previousSession) {
                  sessionHolder.addSession(previousSession)
               }
            }
         }
      }
   }

   def destroy = {}
}
Burt Beckwith
Is there an alternative? I have not upgraded to 1.2, still on 1.1.2
Aaron Saunders