We're using Hibernate 2.1.6 and are butting into the following exception, which we suspect is related to scrolling (althoug we're still trying to isolate the bug):
Code:
Caused by: net.sf.hibernate.HibernateException: Found two representations of same collection: com.sample.Company.SiteSet
at net.sf.hibernate.impl.SessionImpl.updateReachableCollection(SessionImpl.java:2870)
at net.sf.hibernate.impl.FlushVisitor.processCollection(FlushVisitor.java:32)
at net.sf.hibernate.impl.AbstractVisitor.processValue(AbstractVisitor.java:69)
at net.sf.hibernate.impl.AbstractVisitor.processValues(AbstractVisitor.java:36)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2592)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2458)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2260)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2239)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
Looking at the source for SessionImpl, it's not clear what's leading to this bug -- it seems like the Session failes to find a Collection in the session cache that it expects to be there.
This exception is consistently raised on the second iteration through a loop that looks like this:
Code:
ScrollableResults companies = session.getNamedQuery("GetCompanies").scroll();
while ( companies.next() ) {
Company company = (Company) companies.get(0);
// do some stuff that updates the company record
session.flush();
session.clear();
}
session.commit();
The Company and Site are mapped as followed... I've tried setting lazy="false", cascade="none", and inverse="true" and always get the same exception.
Code:
<class name="com.sample.Company" table="company" proxy="com.sample.Company">
....
<set name="SiteSet" lazy="true" where="lifecycle_state_enum_id=1">
<key column="companyId"/>
<one-to-many class="com.sample.Site"/>
</set>
....
</class>
<class name="com.sample.Site" table="site" proxy="com.sample.Site">
....
<property name="companyId" column="company_id" type="com.sample.Company"/>
....
</class>
Any help or insight into this problem would be much appreciated!