• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How JDBC is faster than hibernate?

 
himashree rawat
Greenhorn
Posts: 9
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,
I am new to hibernate so can anybody give a brief idea about how JDBC is faster than hibernate?
Thanks,
Hims
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15627
46
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who says that JDBC is faster than Hibernate? That isn't necessarily true.
 
Campbell Ritchie
Sheriff
Posts: 51344
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
himashree rawat
Greenhorn
Posts: 9
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:And welcome to the Ranch


Thanks but in most of the blogs it has been written that one of the disadvantages of Hibernate over JDBC is that , hibernate is slower than JDBC as multiple queries run at runtime in hibernate,thats what i didn't understand,therefore came up with the question.
Details have not been provided as to how JDBC is faster, in one of the blogs it was practically proven by running the same set of queries in JDBC as well as hibernate and JDBC was much faster so just want to know how come JDBC is faster.
Thanks,
Hims


 
Winston Gutkowski
Bartender
Pie
Posts: 10571
64
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
himashree rawat wrote:Details have not been provided as to how JDBC is faster...

Well, one thing is that with native JDBC you can use PreparedStatements, which Hibernate may not be able to do as easily (or at all). It uses a hybrid query language called HQL, which probably gets translated to SQL as and when needed, which may make them more difficult to cache.

But the fact of the matter is: Do you care?

Speed is only something you should be worried about if/when you KNOW that your application is running too slowly; and since there are thousands of sites out there that have been running Hibernate perfectly happily for years, I wouldn't be "scared off" using it by the dire predictions of some theoretical geeks who live only to benchmark things in ivory tower labs.

Also: You should always consider the source of statements like this. Could it be that they're trying to sell you something? - for example, a "better" Hibernate?
"Send $199 by return of post, and we'll solve all your speed problems..."

Winston
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, Hibernate is a layer on top of JDBC, so right from the start, it's reasonable to assume that it will be slower compared to meticulously hand-crafted JDBC code. And it is true that Hibernate runs a lot more SQL queries than hand-crafted SQL would, particularly ones that return very little data (single ID values, for example), and that is generally not good for network performance. But I think you would need to have a very large application before you started to notice an impact from that. And as Winston mentioned, many large applications are indeed using Hibernate successfully.
 
Ivan Jozsef Balazs
Rancher
Posts: 986
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if have spotted a performance bottleneck, you can still consider repairing it (and only it) with native JDBC.
 
Oscar Vicente
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to speed up your application, make an abstract class that extends HashMap<Data> and make a class that can manage it and make queries with the keys and the data on the HashMap. As you know everything of your program, you can easily get it faster. But build it since the beginning. You can use java annotation interface like Hibernate, but with your own code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic