Xilang
Xilang

Reputation: 1513

GORM,get org.hibernate.HibernateException: Found two representations of same collection when open transaction in afterLoad()

class A {
  def afterLoad() {
    A.withTransaction {

    }
  }
}

Most case, it works, until I call below list in controller

A.createCriteria().list{.....}

will throw exception:org.hibernate.HibernateException: Found two representations of same collection

If I remove

A.withTransaction

It will then works.

Upvotes: 1

Views: 1412

Answers (2)

jonathan.cone
jonathan.cone

Reputation: 6706

I've come across this exception myself and I was really stumped on it for a few days. You can see if the solution to this question solves your problem:

HibernateException: Found two representations of same collection

That solution didn't work for me, so I wrote an article describing the issue and what I did to solve it that you can read here. I believe your problem is similar to mine because of the transactional aspect, Hibernate is flushing the session when the transaction is committed and that's where the exception is thrown.

Upvotes: 0

jenk
jenk

Reputation: 1043

may be

A.withNewSession { session ->
  ....
}

will help you

Upvotes: 1

Related Questions