在 grails 验证器中包含查询时出现堆栈溢出

发布于 2024-08-16 09:28:37 字数 1587 浏览 7 评论 0原文

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

堆栈跟踪:

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)
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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无言温柔 2024-08-23 09:28:37

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

编辑:为 1.1.x 添加:

如果您尚未使用 1.2 并且 withNewSession() 不可用,您可以自己将其连接到引导程序:

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 = {}
}

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 = {}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文