Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Too many queries , JDBC vs Hibernate

 
Saurabh Pillai
Ranch Hand
Posts: 524
  • 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.
 
Paul Sturrock
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: 524
  • 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: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic