Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate advantage? [closed]

Tags:

java

c#

hibernate

Any one can give me the gist of the main advantage of using Hibernate?

like image 574
user496949 Avatar asked Feb 26 '23 20:02

user496949


2 Answers

Hibernate lets you develop a maintainable data access layer with relative ease.

Hibernate is built on top of JDBC, so obviously it cannot do anything that plain JDBC cannot do. Hibernate is a large codebase; if you are building your own data access layer using plain JDBC, you will have lot more code to write to match its features. In simple reporting applications, it is relatively easy to code up the data access layer features you need; but as the application gets more complicated, the amount of code one has to write increases. Let me give you few examples that are non-trivial to implement by hand, but comes out of the box with Hibernate:

  1. Ensuring a global lock acquisition ordering
  2. Determining which fields of an object has changed and tailoring the query appropriately (may not be a good idea always)
  3. Flexibility to switch between various fetch strategies ("here I want the User and Address loaded together, but here I just want User only") in different usecases

As I hinted before, implementing these by hand is not impossible - afterall, Hibernate does it. But they take significant investment in time. In many (most?) applications, concentrating on the complexities of the business logic would be a better investment of developer time.

Please see my comment in another thread regarding Hibernate performance.

like image 141
Binil Thomas Avatar answered Mar 06 '23 23:03

Binil Thomas


I've found it useful if you need your application to work with several different databases. Hibernate will make it much easier to swap out a MySql DB with an Oracle one for example.

like image 43
Joel Avatar answered Mar 07 '23 00:03

Joel