-->
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: Queries slow with more intialised entities during transactio
PostPosted: Tue Mar 06, 2007 10:09 pm 
Newbie

Joined: Thu Jun 22, 2006 12:11 am
Posts: 14
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.2.GA

Code between sessionFactory.openSession() and session.close():


Code:
session.beginTransaction();

for (Campaign camp : campaigns) {

          for (Lot lot : (Set<Lot>)camp.getLots()) {
            Hibernate.initialize(lot.getCampaign());
            Hibernate.initialize(lot.getMsds());
            Hibernate.initialize(lot.getLotAssgns());
           
            for (LotAssgn lotAssgn : (Set<LotAssgn>)lot.getLotAssgns()) {
              Hibernate.initialize(lotAssgn.getTrnfm());

              Hibernate.initialize(lotAssgn.getTrnfm().getLotAssgns());
             
              Hibernate.initialize(lotAssgn.getTrnfm().getMatl());

              if( lotAssgn.getTrnfm().getMatl() != null ){
                Hibernate.initialize(lotAssgn.getTrnfm().getMatl().getYard() );
                Hibernate.initialize(lotAssgn.getTrnfm().getMatl().getYard().getYdgrp() );
              }
             
              Hibernate.initialize(lotAssgn.getLotNwAssgns());

              Hibernate.initialize(lotAssgn.getLot());
              Hibernate.initialize(lotAssgn.getLot().getCampaign());
            }
           
            //get the Msds, intialise
            for (Msd msd : (Set<Msd>)lot.getMsds()) {
              Hibernate.initialize(msd.getLotNwAssgns());
              Hibernate.initialize(msd.getMs());
              Hibernate.initialize(msd.getMs().getMssgl());
              Hibernate.initialize(msd.getMs().getMsds());
              Hibernate.initialize(msd.getMs().getDddes());
              Hibernate.initialize(msd.getMs().getMbook());
              Hibernate.initialize(msd.getMs().getMbook().getCoi());
              Hibernate.initialize(msd.getMs().getMbook().getCoi().getMbooks());
              Hibernate.initialize(msd.getMs().getMddes());
              Hibernate.initialize(msd.getMs().getSddes());
              Hibernate.initialize(msd.getMs().getWcmaByNxtwc());
              Hibernate.initialize(msd.getMs().getWcmaByWcCd());
             
                           
            }


        Query q1 = session.createQuery("from Cntl cntl where cntl.key = 'BW_EUSR'");
        long t1 = System.currentTimeMillis();
        q1.list();
        System.out.println("t1 = " + ( System.currentTimeMillis() - t1 ));

}



Name and version of the database you are using:
Oracle9i Enterprise Edition Release 9.2.0.4.0


Ok alittle extra info, the Campaign loop goes through 5 times (currently) each campaign has 90 - 100 Lot's and each Lot has 1 - 11 Msd's (average 2), with all the intialisation done there are around 2000 entities loaded.

The problem I am having is every time the campaign loop goes through, the time taken to execute _ANY_ query jumps, by the end of all the campaign loops and intialisations it takes around 2 seconds to do even a simple query like the one shown, now if i _DO NOT_ begin the transaction it runs along fine, but even if after the intialisation i start the transaction all subsequent querying slows down to uselessness, now is this meant to happen or have I done something wrong, or perhaps hibernate is not acting as it should, though I assume that seen as though so many entities are loaded that whenever I do a query hibernate must check through the cache which takes alot of time :\


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 07, 2007 9:10 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
I think this is due to automatic dirty checking. Each time hibernate does a flush (each time you query the database) hibernate looks into its session to see if there is any update to do in the database.

If you are only querying objects you can set the flush mode of the session to MANUAL and hibernate won't flush the session when you do a query

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


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.