我正在关注基于Grails 2的书籍示例(Grails in Action 2nd Edition),但我使用的是新的Grails 3.0.1.
当我创建一个看起来像这样的域类:
package qotd
class Quote {
String content
String author
Date created = new Date()
}
Run Code Online (Sandbox Code Playgroud)
每当我尝试通过groovy控制台与DB交互时,我都会抛出异常.
org.springframework.dao.DataAccessResourceFailureException: Could not obtain current Hibernate Session;
Caused by: org.hibernate.HibernateException: No Session found for current thread
Run Code Online (Sandbox Code Playgroud)
我试图将@Transactional添加到域类中,并且还切换到较低的JDK版本(7),但它们都不起作用.我也用Grails 3.0测试过,结果是一样的.如果我降级到Grails 2.5.0它的工作原理是Grails 3.*问题.Gradle可能是个问题.
小智 7
我把一切都包含在Grails 3的一个事务中
qotd.Quote.withTransaction {
new qotd.Quote(author: 'Larry Wall',
content: 'There is more than one method to our madness.').save()
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1743 次 |
| 最近记录: |