-->
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: Deleting collections and cache
PostPosted: Fri Sep 03, 2004 10:42 am 
Newbie

Joined: Fri Sep 03, 2004 8:19 am
Posts: 1
Hibernate version:2.1.4
Name and version of the database you are using:
MS SQL


Essential fragments of mapping documents:
Code:
<hibernate-mapping>
    <class
        name="com.comarch.pc.importd.db.TmpTransaction"
        table="LCT_TMP_TRANSACTIONS"
        dynamic-update="false"
        dynamic-insert="false"
    >
        <id name="id" column="TTR_ID"
            type="int" unsaved-value="0">
            <generator class="native">
            </generator>
        </id>
        <set
            name="tmpDetails"
            lazy="false"
            inverse="true"
            cascade="all-delete-orphan"
            sort="unsorted"
            order-by="TTD_ID"
        >
              <key column="TTD_TTR_ID"/>
              <one-to-many
                  class="com.comarch.pc.importd.db.TmpTrnDetail"/>
        </set>
         <!-- other properties -->
    </class>
</hibernate-mapping>

<hibernate-mapping>
    <class
        name="com.comarch.pc.importd.db.TmpTrnDetail"
        table="LCT_TMP_TRN_DETAILS"
        dynamic-update="false"
        dynamic-insert="false"
    >
        <id name="id" column="TTD_ID"
            type="int" unsaved-value="0">
            <generator class="native"/>
        </id>

        <many-to-one
            name="tmpTransaction"
            class="com.comarch.pc.importd.db.TmpTransaction"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
            column="TTD_TTR_ID"
            not-null="true"
        />
        <!-- other properties -->
    </class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
            net.sf.hibernate.Transaction tx = session.beginTransaction();
           
            // Load TmpTransaction with it's TmpDetails
            TmpTransaction tmpTxn =
                (TmpTransaction)session.get(TmpTransaction.class, new Integer(76097));
            System.out.println("Transaction:"+tmpTxn.toString());
            Set details = tmpTxn.getTmpDetails();
            System.out.println("Details:"+details.size());

            // Delete TmpTransaction with it's TmpDetails
            session.delete(tmpTxn);
            System.out.println("After delete");
            tx.commit();
            System.out.println("After commit");

            // Empty transaction - only for printing state of cache
            System.out.println("new transaction");
            tx = session.beginTransaction();
            System.out.println("Commit");
            tx.commit();


Output (<!-- --> - my comments):
Code:
[DEBUG]:net.sf.hibernate.transaction.JDBCTransaction: begin
....
<---- loading TmpTransaction and it's TmpDetails ------------------------->
[DEBUG]:net.sf.hibernate.impl.SessionImpl: loading [com.comarch.pc.importd.db.TmpTransaction#76097]
....
[DEBUG]:net.sf.hibernate.impl.SessionImpl: initializing collection [com.comarch.pc.importd.db.TmpTransaction.tmpDetails#76097]
....
[DEBUG]:net.sf.hibernate.impl.SessionImpl: collection fully initialized: [com.comarch.pc.importd.db.TmpTransaction.tmpDetails#76097]
....
Transaction:ID:76097
Details:4
Before delete tmpTxn
<---- delete TmpTransaction ------------------------------------------------->
[DEBUG]:net.sf.hibernate.impl.SessionImpl: deleting a persistent instance
[DEBUG]:net.sf.hibernate.impl.SessionImpl: deleting [com.comarch.pc.importd.db.TmpTransaction#76097]
[DEBUG]:net.sf.hibernate.engine.Cascades: processing cascades for: com.comarch.pc.importd.db.TmpTransaction
[DEBUG]:net.sf.hibernate.engine.Cascades: cascading to collection: com.comarch.pc.importd.db.TmpTransaction.tmpDetails
[DEBUG]:net.sf.hibernate.engine.Cascades: cascading to delete()
[DEBUG]:net.sf.hibernate.impl.SessionImpl: deleting a persistent instance
[DEBUG]:net.sf.hibernate.impl.SessionImpl: deleting [com.comarch.pc.importd.db.TmpTrnDetail#179292]
<----        deleting TmpTrnDetail x4 --------------------------------------->
....
[DEBUG]:net.sf.hibernate.engine.Cascades: done processing cascades for: com.comarch.pc.importd.db.TmpTransaction
[DEBUG]:net.sf.hibernate.engine.Cascades: processing cascades for: com.comarch.pc.importd.db.TmpTransaction
[DEBUG]:net.sf.hibernate.engine.Cascades: done processing cascades for: com.comarch.pc.importd.db.TmpTransaction
After delete
<----   commit -------------------------------------------------------------->
[DEBUG]:net.sf.hibernate.transaction.JDBCTransaction: commit
[DEBUG]:net.sf.hibernate.impl.SessionImpl: flushing session
[DEBUG]:net.sf.hibernate.impl.SessionImpl: Flushing entities and processing referenced collections
[DEBUG]:net.sf.hibernate.impl.SessionImpl: Processing unreferenced collections
[DEBUG]:net.sf.hibernate.impl.SessionImpl: Collection dereferenced: [com.comarch.pc.importd.db.TmpTransaction.tmpDetails#76097]
<-----                     ^^^^^^^^^^^^^^^^^^^^^^^^   ------->
[DEBUG]:net.sf.hibernate.impl.SessionImpl: Scheduling collection removes/(re)creates/updates
[DEBUG]:net.sf.hibernate.impl.SessionImpl: Flushed: 0 insertions, 0 updates, 5 deletions to 5 objects
[DEBUG]:net.sf.hibernate.impl.SessionImpl: Flushed: 0 (re)creations, 0 updates, 1 removals to 1 collections
[DEBUG]:net.sf.hibernate.impl.Printer: listing entities:
[DEBUG]:net.sf.hibernate.impl.Printer: com.comarch.pc.importd.db.TmpTransaction{..., tmpDetails=[TmpTrnDetail#179292, TmpTrnDetail#179293, TmpTrnDetail#179294, TmpTrnDetail#179295], id=76097}
[DEBUG]:net.sf.hibernate.impl.Printer: com.comarch.pc.importd.db.TmpTrnDetail{...}
<------   x4                             ------------------------------------>
[DEBUG]:net.sf.hibernate.impl.SessionImpl: executing flush
[DEBUG]:net.sf.hibernate.persister.EntityPersister: Deleting entity: [com.comarch.pc.importd.db.TmpTrnDetail#179292]
[DEBUG]:net.sf.hibernate.impl.BatcherImpl: about to open: 0 open PreparedStatements, 0 open ResultSets
[DEBUG]:net.sf.hibernate.SQL: delete from LCT_TMP_TRN_DETAILS where TTD_ID=?
[DEBUG]:net.sf.hibernate.impl.BatcherImpl: preparing statement
[DEBUG]:net.sf.hibernate.type.IntegerType: binding '179292' to parameter: 1
[DEBUG]:net.sf.hibernate.impl.BatcherImpl: Adding to batch
<------    x4 --------------------------------------------------------------->
....
[DEBUG]:net.sf.hibernate.impl.BatcherImpl: about to open: 0 open PreparedStatements, 0 open ResultSets
[DEBUG]:net.sf.hibernate.SQL: delete from LCT_TMP_TRANSACTIONS where TTR_ID=?
.....
[DEBUG]:net.sf.hibernate.impl.SessionImpl: transaction completion
After commit
new transaction
<---- empty transaction for printing state of cache ---------------------->
[DEBUG]:net.sf.hibernate.transaction.JDBCTransaction: begin
[DEBUG]:net.sf.hibernate.transaction.JDBCTransaction: current autocommit status:false
Commit
[DEBUG]:net.sf.hibernate.transaction.JDBCTransaction: commit
[DEBUG]:net.sf.hibernate.impl.SessionImpl: flushing session
[DEBUG]:net.sf.hibernate.impl.SessionImpl: Flushing entities and processing referenced collections
[DEBUG]:net.sf.hibernate.impl.SessionImpl: Processing unreferenced collections
[DEBUG]:net.sf.hibernate.impl.SessionImpl: Scheduling collection removes/(re)creates/updates
[DEBUG]:net.sf.hibernate.impl.SessionImpl: Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
[DEBUG]:net.sf.hibernate.impl.SessionImpl: Flushed: 0 (re)creations, 0 updates, 0 removals to 1 collections
<----                      ^^^^^^^^^^^^^^ -->
[DEBUG]:net.sf.hibernate.impl.SessionImpl: executing flush
[DEBUG]:net.sf.hibernate.impl.SessionImpl: post flush
[DEBUG]:net.sf.hibernate.impl.SessionImpl: transaction completion



Description of problem:

There is loaded object TmpTransaction with collection of relative objects TrnDetails. When it is deleting, relative TrnDetails are also deleting. "Cascading" works correctly.
Unwanted effect is, that collection is not evicted from session cache.
When this fragment of code is running in loop, number of cached collections increase drammaticaly. Process get more and more system memory and works slower and slower.

Is there something wrong in my code? Or is it a bug in Hibernate?
Maybe is there another way to remove these collections from session?
"session.evict(details)" doesn't work. I can't completly clear cache (session.clear()) in this case.


Best regards
Lukasz


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 1:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Submit this to JIRA. Its sub-optimal behavior.


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.