• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Too many queries , JDBC vs Hibernate  RSS feed

 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider this scenario,

Table A : aId (PK) Table B : bId (PK) Table C : cId (PK), aId (FK), bId (FK)

Now, I want to add one row into table C,

Hibernate :

- Load table A object (1 query)
- Load table B object (1 query)
- Set both objects into table C object.
- Save table C object (1 query)

JDBC :

- Save table C object directly using insert query.


Why hibernate is costlier in this case? and not only in this case same for delete too. I know the benefits of Hibernate.

Thank you.
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why hibernate is costlier in this case?


Not sure you are understanding what Hibernate is for. Hibernate needs to load objects in order to manage them, this is the first step in any operation it does. You can't have any of the benefits of Hibernate (or any other ORM) without it.


 
Saurabh Pillai
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Sturrock wrote:
Not sure you are understanding what Hibernate is for. Hibernate needs to load objects in order to manage them, this is the first step in any operation it does. You can't have any of the benefits of Hibernate (or any other ORM) without it.



I am pointing out a specific case , adding a new record. I want to know if I am doing something wrong?

So there is tread-offs between using Hibernate and JDBC. If you use JDBC then you lose Hibernate benefits , but at the same time, for above specific case, hibernate uses more queries compared with JDBC.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically yes - you're not doing something wrong, but you do have to accept the trade-offs to get the benefits of Hibernate.
 
Saurabh Pillai
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!