-->
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.  [ 3 posts ] 
Author Message
 Post subject: slow query
PostPosted: Mon Jun 19, 2006 11:47 am 
Newbie

Joined: Wed Mar 22, 2006 3:22 pm
Posts: 9
Hibernate version:
3.0

Mapping documents:
NA

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

Full stack trace of any exception that occurs:
NA

Name and version of the database you are using:
Oracle 9i

The generated SQL (show_sql=true):
select count(*) as y0_ from A.TableA this_ where this_.IS_ACTIVE = 'Y' and (this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ?)

Debug level Hibernate log excerpt:
DEBUG [main] (SessionFactoryImpl.java:295) - instantiated session factory
INFO [main] (SessionFactoryImpl.java:427) - Checking 0 named queries
DEBUG [main] (SessionFactory.java:181) - Opening new Session for this thread.
DEBUG [main] (SessionImpl.java:270) - opened session at timestamp: 4713395636924416
DEBUG [main] (AbstractBatcher.java:344) - select count(*) as y0_ from A.TableA this_ where this_.IS_ACTIVE = 'Y' and (this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or this_.Column1 like ? or ... (shorten for readibility)
DEBUG [main] (Loader.java:682) - processing result set
DEBUG [main] (Loader.java:687) - result set row: 0
DEBUG [main] (Loader.java:1164) - result row:
DEBUG [main] (Loader.java:709) - done processing result set (1 rows)
DEBUG [main] (StatefulPersistenceContext.java:780) - initializing non-lazy collections
DEBUG [main] (SessionFactory.java:201) - Closing Session of this thread.
DEBUG [main] (SessionImpl.java:289) - closing session
DEBUG [main] (SessionImpl.java:423) - after transaction completion


I am having an issue with the query above. I shorten the query because the original would repeat the "this_.Column1 like ?" about 2500 times. I would use IN() but you can;t use wildcards such as % within IN. When I execute the query in TOAD the response is almost immediate but within Hibernate it takes about 2-3 minutes. I think this is odd considering I am executing a count. The only difference between TOAD and Hibernate is Hibernate is using ? and in TOAD I have replaced ? with the actual values.

I am not sure why Hibernate is taking so long.


Top
 Profile  
 
 Post subject: any mapping files?
PostPosted: Mon Jun 19, 2006 3:27 pm 
Newbie

Joined: Wed Oct 19, 2005 10:52 am
Posts: 2
Do you have any mapping files? I am wondering why would Hibernate generate that where clause multiple times?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 3:54 pm 
Newbie

Joined: Wed Mar 22, 2006 3:22 pm
Posts: 9
It should repeat the like because I am restricting the column to what the user passed in. So, the user could pass in '1234567', '1235234', '98556%', '56701345' and therefore column1 would be restricted to '1234567' or '1235234' or '98556%' or '56701345'


Code:
public static int getRowCount(List<String> arg) {
  log.debug("getRowCount");
  Integer ret = null;
  if (null != arg) {
    ret = (Integer)SessionFactory.getSession().createCriteria(TableA.class)
               .setProjection(Projections.rowCount())
               .add(restrictColumn1(arg)).uniqueResult();
  }
  return ret;   
}
      
private static Junction restrictColumn1(List<String> args) {
  Junction junction = Restrictions.disjunction();
  for (String arg : args)
    junction.add(Restrictions.like("Column1", arg));
  return junction;
}


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