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.  [ 2 posts ] 
Author Message
 Post subject: JoinedIterator could not be closed with Hibernate.close(i)
PostPosted: Fri Dec 05, 2008 9:54 pm 
Newbie

Joined: Wed Sep 17, 2008 2:59 am
Posts: 10
Hibernate version: 3.1.2

Mapping file:
Code:
<hibernate-mapping>
    <class name="Transaction" table="TRN021" dynamic-update="true" select-before-update="false">
       <cache usage="read-write"/>
        <id name="transactionId" type="integer">
            <column name="TRN021_TRNIDE" precision="22" scale="0" />
            <generator class="sequence">
               <param name="sequence">TRN021s</param>
            </generator>
        </id>
        <discriminator formula="case when TRN021_TRNTYP in ('*CTR','*CTRADJ') then
           TRN021_TRNTYP || case when TRN021_PMEIDE is not null then 'DET' else 'HDR' end
            else '*NOSUBCLASS' end" type="string"/>
      <version name="_auditSequence" access="field" type="integer">
          <column name="TRN021_COFSEQ" not-null="true" />
      </version>
<property name="transactionType" type="string">
    <column name="TRN021_TRNTYP" length="20" not-null="true" />
</property>
<!-- other properties snipped -->
       <subclass name="ContributionAdjustmentDetail" dynamic-update="true" discriminator-value="*CTRADJDET">
           <join table="CTR041" fetch="select">
               <key column="CTR041_TRNIDE"/>
               <property name="headerId" type="int">
                  <column name="CTR041_HEAIDE"/>
              </property>
              <property name="contributionId" type="int">
                  <column name="CTR041_CTRIDE"/>
              </property>
              <property name="cycleCode" type="string">
                  <column name="CTR041_CYCCOD" length="20" not-null="false"/>
              </property>
              <property name="cycleNumber" type="int">
                  <column name="CTR041_CYCNUM"/>
              </property>     
            </join>
         </subclass>
<!-- Other subclasses snipped -->
    </class>
</hibernate-mapping>



HQL query:
Code:
from ContributionAdjustmentDetail detail
where
detail.headerId = :contributionAdjustmentTransactionId and
detail.status <> '9'
order by detail.contributionId, detail.referenceId



Code executing the query:
Code:
      Query query = session.createQuery(CONTRIBUTION_ADJUSTMENT_DETAILS_HQL);
      query.setInteger("contributionAdjustmentTransactionId", 123);
      Iterator<ContributionAdjustmentDetail> iterator = (Iterator<ContributionAdjustmentDetail>) query.iterate();



Closing the iterator returned from the query:
Code:
Hibernate.close( iterator );



Full stack trace of any exception that occurs:
Code:
java.lang.IllegalArgumentException: not a Hibernate iterator
   at org.hibernate.Hibernate.close(Hibernate.java:401)



Hibernate's code in Hibernate.close():
Code:
   public static void close(Iterator iterator) throws HibernateException {
      if ( iterator instanceof HibernateIterator ) {
         ( ( HibernateIterator ) iterator ).close();
      }
      else {
         throw new IllegalArgumentException( "not a Hibernate iterator" );
      }
   }



From the above, you can see that I am trying to close an iterator returned from a query. The query happens to involve implicit polymorphism, since I am querying against a subclass that uses the table per subclass using a discriminator inheritance strategy.

The iterator returned was a JoinedIterator, which does not extend HibernateIterator. Thus, when I try to close / cleanup the iterator, I get the exception above.

How can you explicitly close a JoinedIterator so that the ResultSet / etc. are released ?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 06, 2008 12:10 am 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
It seems that you don't have a choice and you have to wait until the session closes. Maybe you can just close the session if this works for your use case.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.