-->
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.  [ 4 posts ] 
Author Message
 Post subject: New to Hibernate - Performance Issues
PostPosted: Mon May 03, 2010 6:51 pm 
Newbie

Joined: Mon May 03, 2010 6:36 pm
Posts: 5
Hi All

I'm new to Hibernate. It would be great if someone can guide me in the right way. My issue is:

I'm saving about 100 records (maximum is 1000) from the CSV to the DB. The CSV has 7 columns. One of the columns is "PracticeId". Before saving to the DB, I must retrieve 2 more values from a different table based on PracticeId, and then save to the DB. So right now I'm querying the DB about 100 times to retrieve the 2 columns. This takes about 16-17 seconds, which is rather slow. So can anyone help me in optimizing the fetching, so that I can reduce the time drastically. I have some parts of my code here:

pList is the ArrayList(Letter) that has the CSV values
Letter is the class that has to be saved
Practice is the class that has the other 2 values
Code:
for (Letter letter : pList) {      
         
         // Get Demo Id & Id by PracticeId
         Practice practice = new Practice();
         practice = importDao.getPracticeByPracticeId(practiceLetter.getPracticeId());
                  
         // Set Demo ID & Id to PracticeLetter
         if (null != practice) {
            letter.setDemoId(Long.toString(practice.getDemonstrationId()));
            letter.setId(Long.toString(practice.getId()));
}

Then I save the pList to the DB.


This is the method that is called about 100 times (once each for each row in the CSV)
Code:
public Practice getPracticeByPracticeId(final String practiceId) throws DataAccessException {
      return (Practice) this.getHibernateTemplate().execute(new HibernateCallback() {
         public Object doInHibernate(Session session)
         {
            Criteria criteria = session.createCriteria(Practice.class);
            criteria.add(Restrictions.eq("practiceId", practiceId));
            return criteria.uniqueResult();            
         }
       });
   }


Letter & Practice have no relation and pretty straightforward classes.

Hibernate Settings:
Code:
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
        <prop key="hibernate.show_sql">true</prop>
        <prop key="hibernate.max_fetch_depth">3</prop>
        <prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
        <prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
        <prop key="hibernate.generate_statistics">true</prop>
        <prop key="hibernate.cache.use_structured_entries">true</prop>
        <prop key="hibernate.cache.use_query_cache">true</prop>
        <prop key="hibernate.connection.release_mode">after_transaction</prop>     
        <prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>     
        <prop key="hibernate.jdbc.batch_size">50</prop>



Hope I'm clear in my question. Please help me in this regard.


Thanks

Harry


Top
 Profile  
 
 Post subject: Re: New to Hibernate - Performance Issues
PostPosted: Tue May 04, 2010 1:16 pm 
Newbie

Joined: Wed Apr 07, 2010 2:36 pm
Posts: 5
harish7447 wrote:
So right now I'm querying the DB about 100 times to retrieve the 2 columns. This takes about 16-17 seconds, which is rather slow.


Are you sure that your table is set up correctly and you have a adequate connection to you database. 100 fetches on a primary key or index (what I think practiceId would be) shouldn't take that long.


Top
 Profile  
 
 Post subject: Re: New to Hibernate - Performance Issues
PostPosted: Tue May 04, 2010 4:09 pm 
Beginner
Beginner

Joined: Thu Nov 02, 2006 2:23 pm
Posts: 33
Show the SQL you get- it printed to the console.

use named-query to load it.


Top
 Profile  
 
 Post subject: Re: New to Hibernate - Performance Issues
PostPosted: Thu May 06, 2010 5:21 pm 
Newbie

Joined: Mon May 03, 2010 6:36 pm
Posts: 5
sorry for my late replies...

@maple99 - i'm not fetching on the primary key

avihaimar - thank you.

I'm using findByNamedParam and then in the query using in (list) - so now the call to the DB is only once and the performance is a lot better


Harish


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