Example & Tutorial understanding programming in easy ways.

What are the various advantages of Hibernate?

Main Advantages of hibernates are:


1.In hibernate if we save the derived class object,  then its base class object will also be stored into the database, it means hibernate supporting inheritance


2.Hibernate supports Inheritance, Associations, Collections


3.Hibernate supports relationships like One-To-Many,One-To-One, Many-To-Many-to-Many, Many-To-One


4.Hibernate will also supports collections like List,Set,Map (Only new collections)


5.In jdbc all exceptions are checked exceptions, so we must write code in try, catch and throws, but in hibernate we only have Un-checked exceptions, so no need to write try, catch, or no need to write throws.  


6.Actually in hibernate we have the translator which converts checked to Un-checked ;)


7.Hibernate has capability to generate primary keys automatically while we are storing the records into database


8.Hibernate has its own query language, i.e hibernate query language which is database independent


9.So if we change the database, then also our application will works as HQL is database independent


10. HQL contains database independent commands


11.While we are inserting any record, if we don’t have any particular table in the database, JDBC will rises an error like “View not exist”, and throws exception, but in case of hibernate, if it not found any table in the database this will create the table for us ;)


12.Hibernate supports caching mechanism by this, the number of round trips between an application and the database will be reduced, by using this caching technique an application performance will be increased automatically.


13.Hibernate supports annotations, apart from XML


14.Hibernate provided Dialect classes, so we no need to write sql queries in hibernate, instead we use the methods provided by that API.Getting pagination in hibernate is quite simple.


15.Hibernate is data base independent, same code will work for all data bases like ORACLE,MySQL ,SQLServer etc. In case of JDBC query must be data base specific.


16.As Hibernate is set of Objects , you don't need to learn SQL language.You can treat TABLE as a Object . In case of JDBC you need to learn SQL.


17.You will get benefit of Cache. Hibernate support two level of cache. First level and 2nd level. So you can store your data into Cache for better performance. In case of JDBC you need to implement your java cache .


18.Hibernate supports query cache and it will provide the statistics about your query and database status.JDBC Not provides any statistics


19.Development fast in case of Hibernate because you don't need to write queries.


20.You can load your objects on start up using lazy=false in case of Hibernate.JDBC Don't have such support.


21. Hibernate Supports automatic versioning of rows but JDBC Not.

Read More →