I am using hibernate for the first time for one of my projects. One of the entity is Education(StudentObject, CollegeObject, MajorObject, degreeString). To insert Education object into database, i’ve to load student, college and major object from database and then instantiate it and persist. How is this better than just plain sql(insert into..) query? Wouldn’t sql queries be faster, as there is no overhead of loading 3 diff objects from database?
Share
Correct me if I’m wrong but from where do the IDs of the StudentObject, CollegeObject and MajorObject come if not from the database? And if they’re some kind of reference data, they’re perfect candidates for second level caching (and this would mean no database hit at all).
Regardless of your answer, here is my opinion on using an ORM such as Hibernate for a typical CRUD application:
To sum up, the whole point is to improve the productivity of developments and my experience is positive from this point of view. In general, it performs really well, actually even better than custom code (thanks to lazy loading and 2nd level cache).
For some use cases, the performances won’t be “as good” as with custom SQL though. But tuning is possible.
Back to your question, I think the benefits are worth a possible overhead on some use cases (although I’m still not convinced your example is a good one). But do you actually have a performance problem?