I am following a book example (Grails in Action 2nd edition) which is based on Grails 2.* but I am using the new Grails 3.0.1.
When I create a domain class that looks like:
package qotd
class Quote {
String content
String author
Date created = new Date()
}
I get an Exception thrown whenever I try to interact with the DB through the groovy console.
org.springframework.dao.DataAccessResourceFailureException: Could not obtain current Hibernate Session;
Caused by: org.hibernate.HibernateException: No Session found for current thread
I have tried to add @Transactional to the domain class and also swith to a lower JDK version(7) but none of them works. I have also tested with Grails 3.0 and results are same. If I downgrade to Grails 2.5.0 it works so it is a Grails 3.* issue. Gradle could be the issue.
I wrapped everything inside a transaction for Grails 3
qotd.Quote.withTransaction {
new qotd.Quote(author: 'Larry Wall',
content: 'There is more than one method to our madness.').save()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With