-->
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.  [ 5 posts ] 
Author Message
 Post subject: ORM vs. HSQL
PostPosted: Thu Aug 13, 2009 10:37 am 
Newbie

Joined: Thu Aug 13, 2009 9:58 am
Posts: 5
I'm fairly new to Hibernate and I've been testing a few things out. I have a DAO class that has two methods for querying an Oracle database. The first method uses the Criteria API, mappings, and annotated classes. The second method uses HSQL to query the database. Both methods return the same list of 28 objects, however the first method takes much longer than the second.

Initially, using the Criteria API it would take 8000ms or more whereas the HSQL query would only take about 100ms. I implemented second-level caching, query caching, set CacheConcurrencyStrategy.READ_ONLY on any domain objects that I did not need to update and setCacheable(true) on my Criteria object. This helped immensly and reduced to time to about 1000ms. However, this is still 10x slower than using the HSQL query.

Are there additional annotation configurations I can put on my domain objects?

Are there other options for optimizing the Criteria API?

Or is using an HSQL query and manually populating objects always going to be faster than using the Criteria API and having Hibernate create the objects?

Thanks.


Top
 Profile  
 
 Post subject: Re: ORM vs. HSQL
PostPosted: Fri Aug 14, 2009 3:45 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
Compare the generated SQL. Most likely the SQL generated from your handcoded hql is more performant than that created by the annotations engine.
You might be able to tweak that a bit, but likely never to the same extend as handcoded SQL.
If you'd tried another method where you used native SQL queries and highly optimised those, that'd have been faster again.
Had you used sql/plus to execute those same queries, it'd have been faster still.
Fastest of all would have been to have the queries as a view inside the database and call that view from a stored procedure. That would cut out all the network traffic as well as the SQL generation and statement compilation.


Top
 Profile  
 
 Post subject: Re: ORM vs. HSQL
PostPosted: Fri Aug 14, 2009 8:22 am 
Newbie

Joined: Thu Aug 13, 2009 9:58 am
Posts: 5
Well that's rather dissappointing. I thought the point of Hibernate was to speed things up but it appears that it is just to make coding "easier". So if I understand you correctly, I'm better off just using Hiberante for session and transaction management and using hand coded SQL and/or stored proceedures for data interaction.

Thanks for info!


Top
 Profile  
 
 Post subject: Re: ORM vs. HSQL
PostPosted: Fri Aug 14, 2009 2:51 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Quote:
I thought the point of Hibernate was to speed things up


Really, the promise is ease of development, and long term maintainability. Applications that are hard to build are the most difficult one to complete, so hopefully Hibernate helps more projects get completed. Also, the biggest cost of any project is long term maintenance, so something that is easier to understand is also easier to maintain.

I love the criteria. There is no doubt that a well written HQL query might have some performance benefits, but I like the easy to read, and easy to maintain code.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: ORM vs. HSQL
PostPosted: Mon Aug 17, 2009 8:10 am 
Newbie

Joined: Thu Aug 13, 2009 9:58 am
Posts: 5
Cameron,

I totally agree with you. The Criteria API is great for making database interactions neat, clean, and easy to maintain. That's why I was hoping there was some optimization that could be done to make it as fast, or at least close to as fast, as using HQL or a straight JDBC query. If there is no way to speed up the Criteria API and ORM then I might have to resort to using HQL or JDBC.

A bicycle is easier to maintain than a car, but the car will get you there faster.


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