Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails 3.0.1 and Hibernate Session error

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.

like image 837
C.A Avatar asked Mar 16 '23 22:03

C.A


1 Answers

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()
}
like image 163
Chad Hahn Avatar answered Mar 18 '23 13:03

Chad Hahn