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

堆栈跟踪:

测试用例:testFindValidEmailAddress 耗时 0.429 秒
    导致错误
空值
java.lang.StackOverflowError
    在 com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    在 com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    在 com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    在 com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    在 com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    在 com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    在 com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    在 com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    在 com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    在 com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    在 com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    在 com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
    在 com.clearlyINNOVATIVE.model.User$__clinit__closure7_closure13.doCall(User.groovy:36)
4

1 回答 1

8

您应该使用 withNewSession - 请参阅http://adhockery.blogspot.com/2010/01/upgrading-grails-11-12.html

编辑:为 1.1.x 添加:

如果你还没有使用 1.2 并且 withNewSession() 不可用,你可以在 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 = {}
}
于 2010-01-04T22:31:50.883 回答