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,
- 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)
- 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.
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.