-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Problem scrolling objects with Collections
PostPosted: Thu Sep 09, 2004 4:07 am 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
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!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 4:17 am 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
I should mention that we're actually concurrently scrolling through the Company and its Sites -- this is a batch processing use case. So a company's sites have two routes into the Session: via the Company's SiteSet as well as the Site scrollable result set.

We've considered using a separate mapping for this use case that omits the Site set from the Company, but that seems awkward. There doesn't seem to be any intrinsic problem with scrolling through objects that happen to be associated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 4:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You can't use FETCH queries with scroll. (You havn't shown the HQL for some reason, but I'm guessing that this might be what you did.)

If you think about the physics of scroll(), I think you'll see why its not possible.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 4:59 am 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
Thanks for the quick reply!

We don't use FETCH. Here's the Company query:

Code:
<query name="GetCompanies">
select distinct company, group.groupId
from com.sample.Group as group, com.sample.Company as company
where group.companyId = company.id
    and group.batchId = ?
    and group.groupType = ?
    and group.lifecycleState=com.sample.LifecycleState.ACTIVE
order by group.groupId
</query>


The Site scroll query joins on a few other tables (not Company) and also does not use FETCH.

However, I have found something else interesting.

We call Session.update(company) in the middle of the loop. When I commented this out, leaving it to Hibernate to detect changes and schedule updates, things appeared to work -- no exceptions, although I haven't yet examined the output to verify the results.

Why would a "manual update" lead to this problem? And what is the interpretation of the root "Found two representations of same collection" exception?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 5:12 am 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
Hmmm... I suspect I don't understand how Session.update() is supposed to be used or what exactly it does.

Using Session.saveOrUpdateCopy() doesn't seem to cause problems, either.

Gavin, the javadoc is pretty fuzzy for me. I'm sure others have asked about this before, so I'll poke around the forums and wiki for more info.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.