Object-relational mapping or ORM is a programming method for mapping the objects to the relational model where entities/classes are mapped to tables, instances are mapped to rows and attributes of instances are mapped to columns of table.
- Hibernate maps Java classes to database tables using XML files or annotations and without writing any line of code.
- Provides simple APIs for storing and retrieving Java objects directly to and from the database.
- If there is change in Database or in any table then the only need to change XML file properties or entity class.
- Abstract away the unfamiliar SQL types and provide us to work around familiar Java Objects.
- Hibernate does not require an application server to operate.
- Manipulates Complex associations of objects of your database.
- Minimize database access with smart fetching strategies.
- Provides Simple querying of data.
- Hibernate supports Inheritance, Associations, Collections.
- Hibernate supports relationships like One-To-Many,One-To-One, Many-To-Many-to-Many, Many-To-One.
- 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 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 provided Dialect classes, so we no need to write sql queries in hibernate, instead we use the methods provided by that API.
Hibernate DisadvantagesWhen a thing has advantages then it also has some disadvantages also and so does the hibernate:
- It is little slower than pure JDBC, actually the reason being hibernate used to generate many SQL statements in run time. So, JDBC is more beneficial than hibernate for generating reports because of performance issues.
- Little or no capabilities for remote access and distributability.
Supported DatabasesHibernate supports almost all the major RDBMS. Following is list of few of the database engines supported by Hibernate.
- HyperSQL (HSQL)
- Microsoft SQL Server
- SAP DB