grails - 休眠异常 : No Session found for current thread when GORM query moved into another domain class

标签 grails grails-orm

在grails中,我有一个Domain类,可以在BootStap.groovy中查询

def xref = AppXref.find{user_nm == 'john'}

但是,一旦我将代码移动到另一个 Domain 类的方法中,就会出现以下错误。
Servlet.service() for servlet [default] in context with path [/myapp] threw exception
Message: Could not obtain current Hibernate Session; nested exception is org.hibernate.HibernateException: No Session found for current thread

这是我在 Config.groovy 中的休眠配置
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
//    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
    cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
    singleSession = true // configure OSIV singleSession mode
    flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}

我将 cache.use_query_cache 更改为 true。但这并没有什么区别。

最佳答案

添加 @Transactional对我有用的方法。

关于grails - 休眠异常 : No Session found for current thread when GORM query moved into another domain class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27724465/

相关文章:

grails - GORM 事件未在集成测试中触发

grails - 将 SQL 查询转换为 Grails

hibernate - 查询 hasMany 关系的属性

grails - 在Grails中多次重定向响应

sql - Grails顺序不起作用

grails - Grails中的外键异常后更改对象值

tomcat - 在 tomcat 中托管 grails 应用程序

Grails 与静态映射表的关系

Grails:一个数据库和一个以上的应用程序

grails - Grails:动态构建下拉列表时,我想评估列表的名称