-
1. Re: Slow performance of queries and POJO mapping
jc7442 Nov 24, 2006 2:25 AM (in response to markvl)See
http://jira.jboss.com/jira/browse/EJBTHREE-326
and
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=68954&postdays=0&postorder=asc&start=0
Problems is around the flush. If you perform a query with EJB3, a fluish is performed automatically before. It looks like that issues has been fixed in hibernate. It is not yet availabale in JBOSS EJB3 maybe for EJB3 RC10.
To check if flush is you problem, change the FlushModeType. -
2. Re: Slow performance of queries and POJO mapping
markvl Nov 24, 2006 9:14 AM (in response to markvl)Following your suggestion, I tried setting FlushModeType to COMMIT (the only other value supported with EJB3) as follows, but the query is as slow as before.
public List< TestData > select( int accountId, Timestamp timeScheduled ) { Query query = em.createNativeQuery( "select * from test_data where account_id = ? and time_scheduled > ?", TestData.class ).setParameter( 1, accountId ).setParameter( 2, timeScheduled ); query.setFlushMode( FlushModeType.COMMIT ); List< TestData > rows = query.getResultList(); return rows; }
If there was some unexpected flushing going on, wouldn't there be additional calls to the DB server? I have hibernate.show_sql=true and from the logs there are no other queries being executed other than the above select statement. -
3. Re: Slow performance of queries and POJO mapping
jc7442 Nov 24, 2006 1:39 PM (in response to markvl)If you turn hibernate logs off, is it always so slow ?
-
4. Re: Slow performance of queries and POJO mapping
markvl Nov 25, 2006 12:11 AM (in response to markvl)Setting hibernate logging to WARN does help but there is still a signficant performance difference.
Here are the elapsed times with 20 consecutive selects each returning 5000 different rows (averaged over 3 runs excluding the 1st run). Hibernate logging set to WARN.
createQuery(hsql): 11088ms
createNativeQuery(sql): 5573ms
createNativeQuery(sql,class): 7417ms
JDBC: 5052ms
So createQuery is still more than twice as slow as direct JDBC, even with Hibernate logging disabled.
createNativeQuery(sql) is close to the JDBC time, but this excludes the time to generate the POJOs from the list of Objects returned.
Interestingly, createNativeQuery(sql,class) is considerable faster than createQuery even though the underlying query is essentially the same.
So perhaps the best approach is to go with createNativeQuery(sql,class) and then tune as required by rewriting as JDBC calls. -
5. Re: Slow performance of queries and POJO mapping
jc7442 Nov 25, 2006 4:14 AM (in response to markvl)I prefer using ejbql queries. for queries that returns a lot of elements, i do not retrieve all the elements, i uses pages. My gui is not able to display all the elements in once, so the cost of the query is hide by the time needed by the user to request the next page.
It is probably easier to maintain than native query ...