Get all updates of Java4s
Follow Us: Email Newsletter

Main Advantage And Disadvantages Of Hibernates

Hibernate » On May 13, 2011 { 35 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 Author ♦

Java4s_Author
sivateja@java4s.com
Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

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

    hello sir,what are dialect classes?

  2. Java4s says:

    @Nandy

    Answer to your question,

    http://answers.java4s.com/32/what-are-dialect-classes-in-hibernate

    and welcome to answers.java4s.com

  3. NagaSrinu says:

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

  4. mallikarjun says:

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

  5. Java4s says:

    @Mallikarjun

    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?

  9. Java4s says:

    @vignesh

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

  10. Mahish Kumar says:

    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?

  15. Vishal says:

    Hi Sir. Nice Explanation.

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

  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??

  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:

    Hello,
    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:

    @Giri

    Abstract
    -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]

    Interface
    -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.
    https://itroman.wordpress.com/2010/12/05/why-i-do-hate-hibernate/
    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. Aruna Reddy says:

    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…!!!

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
Upcoming
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

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