Main Advantage And Disadvantages Of Hibernates

Hibernate » on May 13, 2011 { 44 Comments } By Sivateja

Let us see what are the advantages and disadvantages of hibernate framework

Advantages of hibernates:

  • Hibernate supports Inheritance, Associations, Collections
  • 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
  • Hibernate supports relationships like One-To-Many,One-To-One, Many-To-Many-to-Many, Many-To-One
  • This will also supports collections like List,Set,Map (Only new collections)
  • 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.  Actually in hibernate we have the translator which converts checked to Un-checked 😉
  • Hibernate has capability to generate primary keys automatically while we are storing the records into database
  • Hibernate has its own query language, i.e hibernate query language which is database independent
  • So if we change the database, then also our application will works as HQL is database independent
  • HQL contains database independent commands
  • 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 😉
  • 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.
  • Hibernate supports annotations, apart from XML
  • 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.


Disadvantages of hibernates:

  • I don’t think there are disadvantages in hibernate
  • You know some thing.., Its saying hibernate is little slower than pure JDBC, actually the reason being hibernate used to generate many SQL statements in run time, but i guess this is not the disadvantage 🙂
  • But there is one major disadvantage, which was boilerplate code issue, actually we need to write same code in several files in the same application, but spring eliminated this


You Might Also Like

  ::. About the Author .::

Sivateja Kandula - Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.


44 Responses to “Main Advantage And Disadvantages Of Hibernates”
  1. Nandy says:

    hello sir,what are dialect classes?

  2. Java4s says:


    Answer to your question,

    and welcome to

  3. NagaSrinu says:

    Hi sir,You’r Way of Expalantation is Awesome..

  4. Hello, Is it possible to configure two databases information in Hibernate.cfg.xml ,if so, how? if not, why? ,Plz. answer.

  5. Java4s says:


    Simple formula….

    No. of Databases = That many Number of Configuration files.

  6. raghu says:

    hi sir first of thanks for posting java related information,i am confused about hibernate associations, so please clarify in real time when we are used

  7. Rahul says:

    how will spring eliminate the duplicate code?

  8. vignesh says:

    what is meant by boilerplate code sir?

    • sanjana says:

      The code which is repeating with minor changes or no changes is called BOILER CODE
      This is the problem which is present JDBC not in HIBERNATE.
      eg: creating Connection, Statement, loading the driver in DriverManagerService, close() are using in every application of JDBC , this we will overcome in HIBERNATE .So there is no BOILERPLATE problem in HIBERNATE

  9. Java4s says:


    boilerplate: Using our source code over and over without change, means can eliminate duplicate code, hope you understood.

  10. what is meant by boilerplate code sir?

  11. balu says:

    your articles are so good ….

  12. thedrs says:

    Another disadvantages:
    – higher learning curve than just using JDBC
    – longer time to implement simple DB solutions (setup, jars config files)
    – need to learn formats of config files and annotations above standard java
    – harder to debug and unhelpful error messages from frame work
    – SQL is standard teaching material in academy – you need to relearn how to perform SQL techniques using hibernate API (e.g., JOINs)

  13. Manish says:

    You site simply superb….!!!!!!

  14. thenna says:

    Could you please explain us how spring eliminates boilerplate code issue?

    • Abhijit says:

      When we use one framework (Spring, Hibernate…) this framework contain some jar class in the from of jar file, This classes will help us for easy and fast development.
      When we required some common functionality we will get it from this class.

  15. Vishal says:

    Hi Sir. Nice Explanation.

  16. Sir What is the use of property….????

    • Abhijit says:

      For creating the table automatically we are using this, many type is there
      1: Validate
      2: Create
      3: Update (recommended)
      4: Create-drop

  17. nandu says:

    Hi can i know whats the meaning of this”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”.

  18. Suresh says:

    Hello Admin:

    as per your words we can have multiple Hibernate.cfg.xml files for different Databases..rite
    So can we interact all Databases with single class by giving config information??

    • Abhijit says:

      If your project required to interact with multiple databases then we required to configure multiple database information in multiple configuration file

  19. Balu says:

    Easily understanding sir, thanks for ur information.

  20. Sidd says:

    What are the precautions needs to take during second level cache?

  21. nice explanation. covered all points thank you

  22. Subash says:

    Dialect is nothing but the ability of hibernate to create query based on the database provided in the configuration file. Normally if we create a query in oracle, then if we need to migrate to mysql then there are lots of changes need to be done to make it compatible with mysql. When we write it in hibernate, it will create the query as per the dialect provided.

  23. Giri says:

    Can u pls include topic related to abstract class and interface…

    Thanks alot for your articles…

    Your explanation is too good.

  24. Souvik Laha says:

    what are dialect classes in hibernate?

  25. srinu says:

    Hi Siva,

    Yours way of explanation is so simple and understandable. here my question is how to change the database from one to other !!

    Ex: for first time my objects were stored in oracle, now i want to change mySql how to do it….?

    thanks in advance…

  26. dinesh kumar says:


    -It contains o or more Abstract methods(that means an abstract class contains concrete method and also abstract method)
    [concrete method- method with body
    Eg: void a()
    int a=b+c;
    [abstract method-method without body]
    Eg: void a();
    -We cannot able to create objects to Abstract class but we can able to create reference variable to it.
    -Abstract class contains Instance variables but Interface does not.
    -If we create abstract method means complier always looks for implementation of that method in its subclass ,otherwise it blink the error.
    – [Mostly abstract class is used at the time of when the think is commonly shared by some people]

    -It contains only abstract methods d as
    -If we did not implement the abstract method in its subclass means than the subclass is declare as abstract
    -It does not contain instance variables(that means variables are public static and final by default)
    -methods are public and abstract by default
    -we cannot able to create object to it but we can able create reference to it

  27. rajeshp says:

    how spring eliminates boilerplate code issue?

  28. Mark says:

    Surprisingly I fully agree with the below link.
    It was rather a very tall claim to say that Hibernate has no disadvantages.
    Your way of explanation is very good(and I really mean it) but needs thorough research before making articles.

  29. Bharath says:

    why Hibernate is better than Other ORM tools ?

  30. santhosh says:

    Hi sivateja, thanks for the article. it’s useful.

  31. hi,

    how to apply union on hibernate query without using criteria query.

  32. Basanta Nahak says:

    Can you please explain how hibernate dialect class works internally?
    Thanks in advance

  33. jenni says:

    1)Is it possible to configure two databases information in Hibernate.cfg.xml ,if so, how? if not, why?
    2)how to configure two databases in hibernate?

  34. Mohit Parley says:

    Please add “Hibernate With Spring” Tutorial…

  35. Abi says:

    Easily Understanding and very easy to learn…!!!

  36. arun singh says:

    Awesome explanation sir

  37. Pramod says:

    Sir can u tell me how to fetch bulk data from mysql using hibernate , bulk data approx 10000000

  38. Mahboob Ali says:

    Hello Sir,
    Hibernate supports relationships like One-To-Many,One-To-One, Many-To-Many-to-Many, Many-To-One

    I think this is wrong typing —-> (Many-To-Many-to-Many)

  39. Anmol says:

    You have explained the topic very well. Thanks for sharing a nice article.


By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2024 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.