Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hibernate v/s stored procedure or functions performance

I am analyzing the options for database layer in my application. I found hibernate a very popular choice however few friends told that better to use stored procedures / function rather than going for hibernate. Hibernate has performance issues compared to these database objects. Is there any other option. My application may have very high volume of transactions so need to select a option which gives a better performance. Can someone put some light on this and help me choose the best option. I am using spring framework as core and richfaces for web layer.

like image 342
Amit Avatar asked May 10 '11 19:05

Amit


People also ask

Which is faster stored procedure or function?

As you can see, the scalar functions are slower than stored procedures. In average, the execution time of the scalar function was 57 seconds and the stored procedure 36 seconds.

Do stored procedures improve performance?

The main performance advantage of a stored procedure is that they have the ability to reuse compiled and cached query plans. In the first execution of a stored procedure, its execution plan is stored in the query plan cache and this query plan is used in the next execution of the procedure.

Are stored procedures faster than ORM?

The bottom line is stored procedures using a DBMS's native SQL language can be orders of magnitude faster than ANY ORM generated SQL. However ORM approach is more maintainable. Most ORM devs are not experts at advanced SQL, and have no understanding/experience of this.

Is hibernate faster?

Hibernate can be fast. Designing a good schema, tuning your queries, and getting good performance is kind of an artform. Remember, under the covers its all sql anyway, so anything you can do with sql you can do with hibernate.


3 Answers

My application may have very high volume of transactions so need to select a option which gives a better performance

Well, if performance is your only (or primary) benchmark, then its hard to beat Oracle packages on the db server. However, your company should consider the strengths of its developers. Is this a shop with mostly Java devs and 1 or 2 lonely Oracle devs and 1 DBA? If so, don't develop your middleware system in Oracle packages, you'll probably have some XML service written in Java using Hibernate. Won't be as fast under load, but will be easier to maintain and grow for YOUR company.

Note: I'm biased towards using Oracle technologies, but thats where my strengths are.

like image 158
tbone Avatar answered Oct 21 '22 15:10

tbone


The best option is you'll figure it out. Sometimes using any ORM is perfectly fine and will support you, other instances it isn't the best option. I think the real answer is it depends on what you're doing, how you're doing it and the quality of product design. All of those make a difference and can greatly dictate a failure or success.

Bottom line, absolutes are a horrible policy -- Use the tech that works and fixes a problem. If it starts being a problem, re-evaluate.

like image 20
jeriley Avatar answered Oct 21 '22 16:10

jeriley


This is pretty late, but I would like to add a few points of using hibernate vs using stored procedures.

From a performance perspective I believe that since writing a stored procedure means you are closer to the database, it would invariably result in a faster output if written efficiently. Consequently hibernate, since its working on the database cannot really be faster than the database. The freedom to optimize queries is something hibernate steals from you and while hibernate may come up with many optimal queries, there may still be some chances for better optimization.

Even pro hibernate developers confess that if you are updating a large dataset, its better to use a procedure rather than make multiple calls with hibernate over the network.

So to summarize I suggest to use procedures and functions for good performance

like image 3
prashant Avatar answered Oct 21 '22 15:10

prashant