Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails & HibernateException: connnection proxy not usable after transaction completion

I just ran into a problem I don't understand. Our grails (2.2.2) app is throwing the following exception just after the first user logged in. Once that one's done, no one has ever seen it again. Currently we're reproducing it with a Geb test.

Caused by HibernateSystemException: connnection proxy not usable after transaction completion; nested exception is org.hibernate.HibernateException: connnection proxy not usable after transaction completion
->>   24 | doCall    in gibbons5.recommender.ActivityRatingTagLib$_closure1

The line in the ActivityRatingTagLib (called by a gsp) is pretty simple:

if (!User.get(session.user.id).permissions.publishStream) {

If I remove the User.get() here and access the session.user right away, everything works fine but then it crashes in the next TagLib call in which the User is accessed via User.get().

I was searching on the internet for solutions a lot now but nothing useful came up yet. As this exception seems to be rather uncommon, I guess we're doing something basically wrong, but what?

User.groovy:

class User implements HttpSessionBindingListener {
    ...

    boolean isOnline = false
    Permissions permissions = new Permissions()

    static embedded = ['infoPopups', 'permissions', 'userSettings']

    void valueBound(HttpSessionBindingEvent event) {
        isOnline = true
    }

    void valueUnbound(HttpSessionBindingEvent event) {
        // we do not have a session any more
        withTransaction {
            def user = get(this.id)
            user.isOnline = false
            user.save()
        }
    }

    ...
}

Permissions.groovy:

class Permissions {
    boolean publishStream = false
}
like image 200
Moritz Avatar asked Nov 24 '22 22:11

Moritz


1 Answers

Had the same exception thrown from a migration script, solved it in the following way (Grails 2.2.0):

User.withNewSession {
    // ...
}
like image 159
ak1ra Avatar answered Nov 26 '22 11:11

ak1ra