简体   繁体   中英

JBoss prepared statement too slow

I have a question, would like to get some help with.
I have the query running from Java.

SELECT DISTINCT field1, field1
from tblTableA WITH (NOLOCK)
WHERE criteriaField='CONSTANT TEXT'

I run it with jpa

  Query qry = entMgr.createNativeQuery(myQry) ;
  List sqlResult = qry.getResultList() ;

Now, that qry.getResultList() takes too much time to run - 75 or more seconds. Yes, it returns close to 700 000 records, but the same query ran on Weblogic 10, using ejb2 runs in less than 5 seconds time

Can anyone help resolving this issue, seems like there maybe a configuration I am missing, or a technique I am not following.

There is something on account of using jbosscmp-jdbc.xml . I don't have that in my set up, but found out that there is a lazy-loading feature that we can configure. Now, I am not sure how make the query I am running be configured in xml file. Also, can this be used with annotations instead of xml file ?

I would try to run this query inside of a non-transactional method:

@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
List getResults(..){
   Query qry = entMgr.createNativeQuery(myQry) ;
   return qry.getResultList() ;
}

This is sometimes not allowed depending on the environment and is mainly used for the optimization of queries expecting to have large results sets and which would later be managed by the PersistenceContext (so basically when you would use HQL instead of native)

But i would give it a try.

You are performing this select query within a transaction scope. I found an old JIRA ticket on Jboos's site. As the ticket suggests, there is a potential around the flush . If you perform a query with EJB3 , a flush is performed or attempted automatically for all the objects you retrieve with your native query. The idea seems to be avoid getting stale objects from the database. But in your case, it is not applicable. Set the flush mode to COMMIT and see if the performance improves.

query.setFlushMode( FlushModeType.COMMIT );

Also turn off the Hibernate logging and see if that makes any difference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM