Получение переполнения стека при включении запроса в валидатор Grails - PullRequest
3 голосов
/ 05 января 2010
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)

1 Ответ

8 голосов
/ 05 января 2010

Вы должны использовать с NewSession - см. http://adhockery.blogspot.com/2010/01/upgrading-grails-11-12.html

Редактировать: добавлено для 1.1.x:

Если вы еще не используете 1.2 и с помощью NewSession () недоступно, выможете подключить его самостоятельно в 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 = {}
}
...