Newsletter |
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 .:: | ||
Comments
44 Responses to “Main Advantage And Disadvantages Of Hibernates”
hello sir,what are dialect classes?
@Nandy
Answer to your question,
http://answers.java4s.com/32/what-are-dialect-classes-in-hibernate
and welcome to answers.java4s.com
Hi sir,You’r Way of Expalantation is Awesome..
Hello, Is it possible to configure two databases information in Hibernate.cfg.xml ,if so, how? if not, why? ,Plz. answer.
@Mallikarjun
Simple formula….
No. of Databases = That many Number of Configuration files.
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
how will spring eliminate the duplicate code?
what is meant by boilerplate code sir?
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
@vignesh
boilerplate: Using our source code over and over without change, means can eliminate duplicate code, hope you understood.
what is meant by boilerplate code sir?
your articles are so good ….
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)
You site simply superb….!!!!!!
Could you please explain us how spring eliminates boilerplate code issue?
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.
Hi Sir. Nice Explanation.
Sir What is the use of hbm2ddl.auto property….????
For creating the table automatically we are using this, many type is there
1: Validate
2: Create
3: Update (recommended)
4: Create-drop
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”.
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??
If your project required to interact with multiple databases then we required to configure multiple database information in multiple configuration file
Easily understanding sir, thanks for ur information.
What are the precautions needs to take during second level cache?
nice explanation. covered all points thank you
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.
Can u pls include topic related to abstract class and interface…
Thanks alot for your articles…
Your explanation is too good.
Hello,
what are dialect classes in hibernate?
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…
@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
how spring eliminates boilerplate code issue?
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.
why Hibernate is better than Other ORM tools ?
Hi sivateja, thanks for the article. it’s useful.
hi,
how to apply union on hibernate query without using criteria query.
Can you please explain how hibernate dialect class works internally?
Thanks in advance
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?
Simple create two *.cfg.xml for two databases and call them
Please add “Hibernate With Spring” Tutorial…
Easily Understanding and very easy to learn…!!!
Awesome explanation sir
Sir can u tell me how to fetch bulk data from mysql using hibernate , bulk data approx 10000000
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)
You have explained the topic very well. Thanks for sharing a nice article.