1
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.

Xilang
  • 1,513
  • 3
  • 18
  • 36

2 Answers2

1

may be

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

will help you

jenk
  • 1,043
  • 7
  • 8
  • I didn't try, I need transaction in these code. Now my walk around is add A.withTransaction around the list{...} code. But I want to know the reason. – Xilang Nov 23 '11 at 01:33
0

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.

Community
  • 1
  • 1
jonathan.cone
  • 6,592
  • 2
  • 30
  • 30