【问题标题】:Grails 3.0.1 and Hibernate Session errorGrails 3.0.1 和休眠会话错误
【发布时间】:2015-08-07 05:01:22
【问题描述】:

我正在关注基于 Grails 2.* 的书籍示例(Grails in Action 第 2 版),但我使用的是新的 Grails 3.0.1。

当我创建一个看起来像这样的域类时:

package qotd

class Quote {
   String content
   String author
   Date created = new Date()
}

每当我尝试通过 groovy 控制台与数据库交互时都会抛出异常。

org.springframework.dao.DataAccessResourceFailureException: Could not obtain current Hibernate Session;
Caused by: org.hibernate.HibernateException: No Session found for current thread

我尝试将@Transactional 添加到域类并切换到较低的JDK 版本(7),但它们都不起作用。 我也用 Grails 3.0 测试过,结果是一样的。 如果我降级到 Grails 2.5.0 它可以工作,所以这是一个 Grails 3.* 问题。 Gradle 可能是问题所在。

【问题讨论】:

标签: grails grails-orm


【解决方案1】:

我将所有内容都包装在 Grails 3 的事务中

qotd.Quote.withTransaction {
  new qotd.Quote(author: 'Larry Wall',
    content: 'There is more than one method to our madness.').save()
}

【讨论】:

    猜你喜欢
    • 2013-05-18
    • 1970-01-01
    • 2014-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-14
    • 1970-01-01
    相关资源
    最近更新 更多